@data-weave/backend-firestore 0.4.26 → 0.5.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/dist/FirestoreAdminAdapter.d.ts +31 -0
- package/dist/FirestoreAdminAdapter.js +106 -0
- package/dist/FirestoreDataManager.d.ts +76 -0
- package/dist/FirestoreDataManager.js +243 -0
- package/{lib → dist}/FirestoreList.d.ts +3 -7
- package/dist/FirestoreList.js +95 -0
- package/{lib → dist}/FirestoreMetadata.d.ts +1 -0
- package/{lib → dist}/FirestoreMetadata.js +3 -3
- package/{lib → dist}/FirestoreReference.d.ts +3 -10
- package/dist/FirestoreReference.js +75 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.js +38 -0
- package/{lib → dist}/firestoreTypes.d.ts +18 -11
- package/dist/firestoreTypes.js +29 -0
- package/{lib → dist}/index.d.ts +3 -0
- package/{lib → dist}/index.js +3 -0
- package/{lib → dist}/utils.d.ts +3 -2
- package/{lib → dist}/utils.js +49 -7
- package/package.json +20 -9
- package/lib/FirestoreDataManager.d.ts +0 -46
- package/lib/FirestoreDataManager.js +0 -227
- package/lib/FirestoreList.js +0 -96
- package/lib/FirestoreReference.js +0 -85
- package/lib/firestoreTypes.js +0 -127
- package/lib/version.d.ts +0 -2
- package/lib/version.js +0 -3
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FirestoreReference = void 0;
|
|
4
|
+
const datamanager_1 = require("@data-weave/datamanager");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
class FirestoreReference extends datamanager_1.LiveReference {
|
|
8
|
+
firestore;
|
|
9
|
+
docRef;
|
|
10
|
+
options;
|
|
11
|
+
unsubscribeFromSnapshot;
|
|
12
|
+
constructor(firestore, docRef, options) {
|
|
13
|
+
super(docRef.id, options);
|
|
14
|
+
this.firestore = firestore;
|
|
15
|
+
this.docRef = docRef;
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
async resolve() {
|
|
19
|
+
if (this.options?.readMode === 'realtime') {
|
|
20
|
+
return new Promise(res => {
|
|
21
|
+
// Unsubscribe from any existing snapshot listener
|
|
22
|
+
if (this.unsubscribeFromSnapshot) {
|
|
23
|
+
this.unsubscribeFromSnapshot();
|
|
24
|
+
}
|
|
25
|
+
this.unsubscribeFromSnapshot = this.firestore.onSnapshot(this.docRef, documentSnapshot => {
|
|
26
|
+
try {
|
|
27
|
+
this.onUpdate(this.parseDocumentSnapshot(documentSnapshot));
|
|
28
|
+
// TODO: When calling ".resolve()" with realtime listener,
|
|
29
|
+
// the snapshot data might be stale from cache.
|
|
30
|
+
res(this.value);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
this.onError(error);
|
|
34
|
+
res(this.value);
|
|
35
|
+
}
|
|
36
|
+
}, error => {
|
|
37
|
+
this.onError(error);
|
|
38
|
+
res(this.value);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const doc = await this.firestore.getDoc(this.docRef);
|
|
44
|
+
this.onUpdate(this.parseDocumentSnapshot(doc));
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
this.onError(error);
|
|
48
|
+
}
|
|
49
|
+
return this.value;
|
|
50
|
+
}
|
|
51
|
+
get path() {
|
|
52
|
+
return this.docRef.path;
|
|
53
|
+
}
|
|
54
|
+
onError(error) {
|
|
55
|
+
const wrapped = new errors_1.FirestoreReferenceError(error, {
|
|
56
|
+
path: this.docRef.path,
|
|
57
|
+
id: this.docRef.id,
|
|
58
|
+
readMode: this.options?.readMode,
|
|
59
|
+
snapshotOptions: this.options?.snapshotOptions,
|
|
60
|
+
type: 'reference',
|
|
61
|
+
});
|
|
62
|
+
super.onError(wrapped);
|
|
63
|
+
}
|
|
64
|
+
unsubscribe() {
|
|
65
|
+
this.unsubscribeFromSnapshot?.();
|
|
66
|
+
this.setStale();
|
|
67
|
+
}
|
|
68
|
+
parseDocumentSnapshot(docSnapshot) {
|
|
69
|
+
if (!(0, utils_1.checkIfReferenceExists)(docSnapshot))
|
|
70
|
+
throw new Error(`Document does not exist ${this.docRef.path}`);
|
|
71
|
+
return docSnapshot.data(this.options?.snapshotOptions);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.FirestoreReference = FirestoreReference;
|
|
75
|
+
//# sourceMappingURL=FirestoreReference.js.map
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { FirestoreReadMode, FirestoreTypes } from './firestoreTypes';
|
|
2
|
+
export interface FirestoreReferenceContext {
|
|
3
|
+
path: string;
|
|
4
|
+
id: string;
|
|
5
|
+
readMode?: FirestoreReadMode;
|
|
6
|
+
snapshotOptions?: FirestoreTypes.SnapshotOptions;
|
|
7
|
+
type: 'reference';
|
|
8
|
+
}
|
|
9
|
+
export interface FirestoreListContext {
|
|
10
|
+
query: FirestoreTypes.Query<unknown>;
|
|
11
|
+
readMode?: FirestoreReadMode;
|
|
12
|
+
type: 'list';
|
|
13
|
+
}
|
|
14
|
+
export declare class FirestoreError extends Error {
|
|
15
|
+
readonly cause: unknown;
|
|
16
|
+
constructor(message: string, cause?: unknown);
|
|
17
|
+
}
|
|
18
|
+
export declare class FirestoreReferenceError extends FirestoreError {
|
|
19
|
+
readonly context: FirestoreReferenceContext;
|
|
20
|
+
constructor(cause: unknown, context: FirestoreReferenceContext);
|
|
21
|
+
}
|
|
22
|
+
export declare class FirestoreListError extends FirestoreError {
|
|
23
|
+
readonly context: FirestoreListContext;
|
|
24
|
+
constructor(cause: unknown, context: FirestoreListContext);
|
|
25
|
+
}
|
|
26
|
+
export declare class FirestoreDataManagerError extends FirestoreError {
|
|
27
|
+
constructor(message: string, cause?: unknown);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FirestoreDataManagerError = exports.FirestoreListError = exports.FirestoreReferenceError = exports.FirestoreError = void 0;
|
|
4
|
+
class FirestoreError extends Error {
|
|
5
|
+
cause;
|
|
6
|
+
constructor(message, cause) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'FirestoreError';
|
|
9
|
+
this.cause = cause;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.FirestoreError = FirestoreError;
|
|
13
|
+
class FirestoreReferenceError extends FirestoreError {
|
|
14
|
+
context;
|
|
15
|
+
constructor(cause, context) {
|
|
16
|
+
super(`FirestoreReference error at "${context.path}"`, cause);
|
|
17
|
+
this.context = context;
|
|
18
|
+
this.name = 'FirestoreReferenceError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.FirestoreReferenceError = FirestoreReferenceError;
|
|
22
|
+
class FirestoreListError extends FirestoreError {
|
|
23
|
+
context;
|
|
24
|
+
constructor(cause, context) {
|
|
25
|
+
super('FirestoreList error', cause);
|
|
26
|
+
this.context = context;
|
|
27
|
+
this.name = 'FirestoreListError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.FirestoreListError = FirestoreListError;
|
|
31
|
+
class FirestoreDataManagerError extends FirestoreError {
|
|
32
|
+
constructor(message, cause) {
|
|
33
|
+
super(message, cause);
|
|
34
|
+
this.name = 'FirestoreDataManagerError';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.FirestoreDataManagerError = FirestoreDataManagerError;
|
|
38
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -2,9 +2,9 @@ import { WithoutId } from '@data-weave/datamanager';
|
|
|
2
2
|
import type * as FirestoreTypes from '@firebase/firestore';
|
|
3
3
|
import type { FieldPath, WithFieldValue as FirestoreWithFieldValue, QueryConstraint } from '@firebase/firestore';
|
|
4
4
|
import type { HttpsCallable, HttpsCallableOptions } from '@firebase/functions-types';
|
|
5
|
-
import type {
|
|
5
|
+
import type { Transaction as AdminTransaction, FieldValue } from '@google-cloud/firestore';
|
|
6
6
|
export type DocumentData = FirestoreTypes.DocumentData;
|
|
7
|
-
export { FieldValue, FirestoreTypes
|
|
7
|
+
export { FieldValue, FirestoreTypes };
|
|
8
8
|
/**
|
|
9
9
|
* Same as Partial but all fields are required to be included
|
|
10
10
|
*/
|
|
@@ -53,6 +53,18 @@ export type OrderBy<T extends DocumentData, Fields extends string = FilterableFi
|
|
|
53
53
|
Fields,
|
|
54
54
|
FirestoreTypes.OrderByDirection
|
|
55
55
|
];
|
|
56
|
+
export type AggregateFieldSpec = {
|
|
57
|
+
readonly type: 'sum' | 'average';
|
|
58
|
+
readonly field: string;
|
|
59
|
+
} | {
|
|
60
|
+
readonly type: 'count';
|
|
61
|
+
};
|
|
62
|
+
export type AggregateSpec = {
|
|
63
|
+
readonly [alias: string]: AggregateFieldSpec;
|
|
64
|
+
};
|
|
65
|
+
export type AggregateResult<T extends AggregateSpec> = {
|
|
66
|
+
[K in keyof T]: number | null;
|
|
67
|
+
};
|
|
56
68
|
export declare abstract class FieldValues {
|
|
57
69
|
abstract serverTimestamp(): FirestoreTypes.FieldValue;
|
|
58
70
|
abstract delete(): FirestoreTypes.FieldValue;
|
|
@@ -60,13 +72,6 @@ export declare abstract class FieldValues {
|
|
|
60
72
|
abstract arrayUnion(...elements: any[]): FirestoreTypes.FieldValue;
|
|
61
73
|
abstract arrayRemove(...elements: any[]): FirestoreTypes.FieldValue;
|
|
62
74
|
}
|
|
63
|
-
/**********
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* INJECTABLES
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* **********/
|
|
70
75
|
export interface FirestoreAppSettings {
|
|
71
76
|
persistence?: boolean;
|
|
72
77
|
cacheSizeBytes?: number;
|
|
@@ -81,12 +86,13 @@ export declare abstract class FirestoreApp {
|
|
|
81
86
|
abstract terminate?(): Promise<void>;
|
|
82
87
|
abstract settings?(settings: FirestoreAppSettings): void;
|
|
83
88
|
abstract useEmulator?(host: string, port: number): void;
|
|
84
|
-
abstract runTransaction?<T>(updateFunction: (transaction:
|
|
89
|
+
abstract runTransaction?<T>(updateFunction: (transaction: AdminTransaction) => Promise<T>, options?: FirestoreTypes.TransactionOptions): Promise<T>;
|
|
85
90
|
}
|
|
86
91
|
export declare abstract class Firestore {
|
|
87
92
|
abstract app: FirestoreApp;
|
|
88
93
|
abstract collection(reference: FirestoreTypes.CollectionReference | FirestoreApp, path: string): any;
|
|
89
94
|
abstract getDocs<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(reference: FirestoreTypes.Query<AppModelType, DbModelType>): Promise<FirestoreTypes.QuerySnapshot<AppModelType, DbModelType>>;
|
|
95
|
+
abstract getAggregateFromServer<Spec extends AggregateSpec>(query: FirestoreTypes.Query, spec: Spec): Promise<AggregateResult<Spec>>;
|
|
90
96
|
abstract getDoc<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(reference: FirestoreTypes.DocumentReference<AppModelType, DbModelType>, path?: string): Promise<FirestoreTypes.DocumentSnapshot<AppModelType, DbModelType>>;
|
|
91
97
|
abstract serverTimestamp(): FirestoreTypes.FieldValue;
|
|
92
98
|
abstract increment(n: number): FirestoreTypes.FieldValue;
|
|
@@ -100,7 +106,7 @@ export declare abstract class Firestore {
|
|
|
100
106
|
abstract deleteDoc<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(reference: FirestoreTypes.DocumentReference<AppModelType, DbModelType>): Promise<void>;
|
|
101
107
|
abstract onSnapshot<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(reference: FirestoreTypes.DocumentReference<AppModelType, DbModelType>, onNext: (snapshot: FirestoreTypes.DocumentSnapshot<AppModelType, DbModelType>) => void, onError?: (error: Error) => void): () => void;
|
|
102
108
|
abstract onSnapshot<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(reference: FirestoreTypes.Query<AppModelType, DbModelType>, onNext: (snapshot: FirestoreTypes.QuerySnapshot<AppModelType, DbModelType>) => void, onError?: (error: Error) => void): () => void;
|
|
103
|
-
abstract runTransaction<T>(firestore: FirestoreApp, transaction: (transaction: Transaction) => Promise<T>, options?: FirestoreTypes.TransactionOptions): Promise<T>;
|
|
109
|
+
abstract runTransaction<T>(firestore: FirestoreApp, transaction: (transaction: FirestoreTypes.Transaction) => Promise<T>, options?: FirestoreTypes.TransactionOptions): Promise<T>;
|
|
104
110
|
}
|
|
105
111
|
export declare abstract class FirestoreSettings {
|
|
106
112
|
abstract readMode: FirestoreReadMode;
|
|
@@ -115,3 +121,4 @@ export declare class DummyFirestoreFunctions implements FirestoreFunctions {
|
|
|
115
121
|
useEmulator(): void;
|
|
116
122
|
useFunctionsEmulator(): void;
|
|
117
123
|
}
|
|
124
|
+
//# sourceMappingURL=firestoreTypes.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DummyFirestoreFunctions = exports.FirestoreFunctions = exports.FirestoreSettings = exports.Firestore = exports.FirestoreApp = exports.FieldValues = void 0;
|
|
4
|
+
class FieldValues {
|
|
5
|
+
}
|
|
6
|
+
exports.FieldValues = FieldValues;
|
|
7
|
+
class FirestoreApp {
|
|
8
|
+
}
|
|
9
|
+
exports.FirestoreApp = FirestoreApp;
|
|
10
|
+
class Firestore {
|
|
11
|
+
}
|
|
12
|
+
exports.Firestore = Firestore;
|
|
13
|
+
class FirestoreSettings {
|
|
14
|
+
}
|
|
15
|
+
exports.FirestoreSettings = FirestoreSettings;
|
|
16
|
+
class FirestoreFunctions {
|
|
17
|
+
}
|
|
18
|
+
exports.FirestoreFunctions = FirestoreFunctions;
|
|
19
|
+
class DummyFirestoreFunctions {
|
|
20
|
+
httpsCallable() {
|
|
21
|
+
return () => {
|
|
22
|
+
throw new Error('httpsCallable not implemented - DummyFirestoreFunctions');
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
useEmulator() { }
|
|
26
|
+
useFunctionsEmulator() { }
|
|
27
|
+
}
|
|
28
|
+
exports.DummyFirestoreFunctions = DummyFirestoreFunctions;
|
|
29
|
+
//# sourceMappingURL=firestoreTypes.js.map
|
package/{lib → dist}/index.d.ts
RENAMED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
export * from './errors';
|
|
2
|
+
export * from './FirestoreAdminAdapter';
|
|
1
3
|
export * from './FirestoreDataManager';
|
|
2
4
|
export * from './FirestoreList';
|
|
3
5
|
export * from './FirestoreMetadata';
|
|
4
6
|
export * from './FirestoreReference';
|
|
5
7
|
export * from './firestoreTypes';
|
|
6
8
|
export * from './utils';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
package/{lib → dist}/index.js
RENAMED
|
@@ -14,9 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./errors"), exports);
|
|
18
|
+
__exportStar(require("./FirestoreAdminAdapter"), exports);
|
|
17
19
|
__exportStar(require("./FirestoreDataManager"), exports);
|
|
18
20
|
__exportStar(require("./FirestoreList"), exports);
|
|
19
21
|
__exportStar(require("./FirestoreMetadata"), exports);
|
|
20
22
|
__exportStar(require("./FirestoreReference"), exports);
|
|
21
23
|
__exportStar(require("./firestoreTypes"), exports);
|
|
22
24
|
__exportStar(require("./utils"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
package/{lib → dist}/utils.d.ts
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WithoutId } from '@data-weave/datamanager';
|
|
2
|
-
import { DocumentData, Firestore, FirestoreTypes, InternalFirestoreDataConverter,
|
|
2
|
+
import { DocumentData, Firestore, FirestoreTypes, InternalFirestoreDataConverter, WithFieldValue } from './firestoreTypes';
|
|
3
3
|
import { Firestore as FirebaseFirestore } from 'firebase/firestore';
|
|
4
4
|
export declare class MergeConverters<T extends DocumentData, SerializedT extends DocumentData, G extends DocumentData, SerializedG extends DocumentData> implements InternalFirestoreDataConverter<T & G, SerializedT & SerializedG> {
|
|
5
5
|
private converter1;
|
|
@@ -11,4 +11,5 @@ export declare class MergeConverters<T extends DocumentData, SerializedT extends
|
|
|
11
11
|
export declare function createModularFirestoreAdapter(firestore: FirebaseFirestore): Firestore;
|
|
12
12
|
export declare const isFieldValue: (value: any) => value is FirestoreTypes.FieldValue;
|
|
13
13
|
export declare const checkIfReferenceExists: (value: any) => boolean;
|
|
14
|
-
export declare const withTransaction: (firestore: Firestore, transaction: (transaction: Transaction) => Promise<void>, options?: FirestoreTypes.TransactionOptions) => Promise<void>;
|
|
14
|
+
export declare const withTransaction: (firestore: Firestore, transaction: (transaction: FirestoreTypes.Transaction) => Promise<void>, options?: FirestoreTypes.TransactionOptions) => Promise<void>;
|
|
15
|
+
//# sourceMappingURL=utils.d.ts.map
|
package/{lib → dist}/utils.js
RENAMED
|
@@ -3,29 +3,72 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.withTransaction = exports.checkIfReferenceExists = exports.isFieldValue = exports.MergeConverters = void 0;
|
|
4
4
|
exports.createModularFirestoreAdapter = createModularFirestoreAdapter;
|
|
5
5
|
const firestore_1 = require("firebase/firestore");
|
|
6
|
+
class ConverterError extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'ConverterError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
6
12
|
class MergeConverters {
|
|
13
|
+
converter1;
|
|
14
|
+
converter2;
|
|
7
15
|
constructor(converter1, converter2) {
|
|
8
16
|
this.converter1 = converter1;
|
|
9
17
|
this.converter2 = converter2;
|
|
10
18
|
}
|
|
11
19
|
toFirestore(modelObject, options) {
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
try {
|
|
21
|
+
if (options) {
|
|
22
|
+
return {
|
|
23
|
+
...this.converter1.toFirestore(modelObject, options),
|
|
24
|
+
...this.converter2.toFirestore(modelObject, options),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return {
|
|
29
|
+
...this.converter1.toFirestore(modelObject),
|
|
30
|
+
...this.converter2.toFirestore(modelObject),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
14
33
|
}
|
|
15
|
-
|
|
16
|
-
|
|
34
|
+
catch (error) {
|
|
35
|
+
throw new ConverterError(`Failed to convert model object to firestore: ${error}`);
|
|
17
36
|
}
|
|
18
37
|
}
|
|
19
38
|
fromFirestore(snapshot, options) {
|
|
20
|
-
|
|
39
|
+
try {
|
|
40
|
+
return {
|
|
41
|
+
...this.converter1.fromFirestore(snapshot, options),
|
|
42
|
+
...this.converter2.fromFirestore(snapshot, options),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw new ConverterError(`Failed to convert snapshot to model object: ${error}`);
|
|
47
|
+
}
|
|
21
48
|
}
|
|
22
49
|
}
|
|
23
50
|
exports.MergeConverters = MergeConverters;
|
|
51
|
+
function buildAggregateSpec(spec) {
|
|
52
|
+
return Object.fromEntries(Object.keys(spec).map(alias => {
|
|
53
|
+
const fieldSpec = spec[alias];
|
|
54
|
+
if (fieldSpec.type === 'count') {
|
|
55
|
+
return [alias, (0, firestore_1.count)()];
|
|
56
|
+
}
|
|
57
|
+
const factory = fieldSpec.type === 'sum' ? firestore_1.sum : firestore_1.average;
|
|
58
|
+
return [alias, factory(fieldSpec.field)];
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
async function modularGetAggregateFromServer(ref, spec) {
|
|
62
|
+
const sdkSpec = buildAggregateSpec(spec);
|
|
63
|
+
const snapshot = await (0, firestore_1.getAggregateFromServer)(ref, sdkSpec);
|
|
64
|
+
return snapshot.data();
|
|
65
|
+
}
|
|
24
66
|
function createModularFirestoreAdapter(firestore) {
|
|
25
67
|
return {
|
|
26
68
|
app: firestore,
|
|
27
69
|
collection: firestore_1.collection,
|
|
28
70
|
getDocs: firestore_1.getDocs,
|
|
71
|
+
getAggregateFromServer: modularGetAggregateFromServer,
|
|
29
72
|
getDoc: firestore_1.getDoc,
|
|
30
73
|
serverTimestamp: firestore_1.serverTimestamp,
|
|
31
74
|
query: firestore_1.query,
|
|
@@ -38,8 +81,6 @@ function createModularFirestoreAdapter(firestore) {
|
|
|
38
81
|
doc: firestore_1.doc,
|
|
39
82
|
onSnapshot: firestore_1.onSnapshot,
|
|
40
83
|
increment: firestore_1.increment,
|
|
41
|
-
// TODO: fix this
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
84
|
runTransaction: firestore_1.runTransaction,
|
|
44
85
|
};
|
|
45
86
|
}
|
|
@@ -63,3 +104,4 @@ const withTransaction = (firestore, transaction, options) => {
|
|
|
63
104
|
return firestore.runTransaction(firestore.app, transaction, options);
|
|
64
105
|
};
|
|
65
106
|
exports.withTransaction = withTransaction;
|
|
107
|
+
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-weave/backend-firestore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"author": "",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"
|
|
9
|
-
"
|
|
8
|
+
"dist/**/*.js",
|
|
9
|
+
"dist/**/*.d.ts"
|
|
10
10
|
],
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@data-weave/datamanager": "~0.5.0",
|
|
13
|
+
"@firebase/firestore": "^4.7.8",
|
|
14
|
+
"@firebase/functions-types": "^0.6.3",
|
|
15
|
+
"@google-cloud/firestore": "^7.11.1",
|
|
16
|
+
"@types/node": "^22.10.2",
|
|
17
|
+
"firebase": "^11.9.0",
|
|
18
|
+
"typescript": "5.9.3"
|
|
19
|
+
},
|
|
11
20
|
"scripts": {
|
|
12
|
-
"clean": "rm -rf
|
|
13
|
-
"build": "
|
|
21
|
+
"clean": "rm -rf dist",
|
|
22
|
+
"build": "tsc",
|
|
14
23
|
"build:clean": "npm run clean && npm run build",
|
|
15
24
|
"prepare": "npm run build"
|
|
16
25
|
},
|
|
@@ -23,8 +32,10 @@
|
|
|
23
32
|
"registry": "https://registry.npmjs.org/"
|
|
24
33
|
},
|
|
25
34
|
"peerDependencies": {
|
|
26
|
-
"@data-weave/datamanager": "~0.4.25",
|
|
27
35
|
"firebase": ">=11.0.0"
|
|
28
36
|
},
|
|
29
|
-
"
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@data-weave/datamanager": "~0.5.0"
|
|
39
|
+
},
|
|
40
|
+
"gitHead": "df44d823b93b392d9e3b685fafb0d17399001291"
|
|
30
41
|
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Cache, DataManager, IdentifiableReference, List, ListPaginationParams, WithMetadata, WithoutId } from '@data-weave/datamanager';
|
|
2
|
-
import { FirestoreList, FirestoreListContext } from './FirestoreList';
|
|
3
|
-
import { FirestoreSerializedMetadata } from './FirestoreMetadata';
|
|
4
|
-
import { FirestoreReference, FirestoreReferenceContext } from './FirestoreReference';
|
|
5
|
-
import { FilterBy, FirebaseCreateOptions, Firestore, FirestoreDataConverter, FirestoreReadMode, FirestoreReadOptions, FirestoreTypes, FirestoreWriteOptions, OrderBy, WithFieldValue } from './firestoreTypes';
|
|
6
|
-
export type FirebaseDataManagerDeleteMode = 'soft' | 'hard';
|
|
7
|
-
export interface FirebaseDataManagerOptions {
|
|
8
|
-
readonly idResolver?: () => string;
|
|
9
|
-
readonly deleteMode?: FirebaseDataManagerDeleteMode;
|
|
10
|
-
readonly readMode?: FirestoreReadMode;
|
|
11
|
-
readonly preventOverwriteOnCreate?: boolean;
|
|
12
|
-
readonly errorInterceptor?: (error: unknown, ctx: FirestoreReferenceContext | FirestoreListContext) => void;
|
|
13
|
-
readonly snapshotOptions?: FirestoreTypes.SnapshotOptions;
|
|
14
|
-
readonly Reference?: typeof FirestoreReference;
|
|
15
|
-
readonly List?: typeof FirestoreList;
|
|
16
|
-
readonly listCache?: Cache;
|
|
17
|
-
readonly refCache?: Cache;
|
|
18
|
-
readonly disableCache?: boolean;
|
|
19
|
-
}
|
|
20
|
-
export interface QueryParams<T> {
|
|
21
|
-
readonly filters?: Array<FilterBy<T & FirestoreSerializedMetadata>>;
|
|
22
|
-
readonly orderBy?: Array<OrderBy<T & FirestoreSerializedMetadata>>;
|
|
23
|
-
}
|
|
24
|
-
export declare class FirestoreDataManager<T extends FirestoreTypes.DocumentData, SerializedT extends FirestoreTypes.DocumentData = T> implements DataManager<T> {
|
|
25
|
-
private readonly firestore;
|
|
26
|
-
private readonly collectionPath;
|
|
27
|
-
private readonly converter;
|
|
28
|
-
private readonly opts?;
|
|
29
|
-
private mergedConverter;
|
|
30
|
-
private collection;
|
|
31
|
-
private collectionQuery;
|
|
32
|
-
private managerOptions;
|
|
33
|
-
private refCache;
|
|
34
|
-
private listCache;
|
|
35
|
-
constructor(firestore: Firestore, collectionPath: string, converter: FirestoreDataConverter<T, SerializedT>, opts?: FirebaseDataManagerOptions | undefined);
|
|
36
|
-
read(id: string, options?: FirestoreReadOptions): Promise<WithMetadata<T> | undefined>;
|
|
37
|
-
create(data: WithFieldValue<WithoutId<T>>, options?: FirebaseCreateOptions): Promise<IdentifiableReference<WithMetadata<T>>>;
|
|
38
|
-
private _update;
|
|
39
|
-
update(id: string, data: WithoutId<Partial<WithFieldValue<T>>>, options?: FirestoreWriteOptions): Promise<void>;
|
|
40
|
-
upsert(id: string, data: WithFieldValue<WithoutId<T>>, options?: FirestoreWriteOptions): Promise<void>;
|
|
41
|
-
delete(id: string, options?: FirestoreWriteOptions): Promise<void>;
|
|
42
|
-
getRef(id: string): IdentifiableReference<WithMetadata<T>>;
|
|
43
|
-
private _getFilteredQuery;
|
|
44
|
-
getList(params?: QueryParams<SerializedT> & ListPaginationParams): List<WithMetadata<T>>;
|
|
45
|
-
private preventOverwriteOnCreate;
|
|
46
|
-
}
|