@nx-ddd/firestore 19.2.1 → 19.3.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/adapters/admin/index.d.ts +40 -1
- package/adapters/firebase/index.d.ts +35 -1
- package/{adapters/admin/admin.adapter.js → fesm2022/nx-ddd-firestore-adapters-admin.mjs} +21 -13
- package/fesm2022/nx-ddd-firestore-adapters-admin.mjs.map +1 -0
- package/{adapters/firebase/firebase.adapter.js → fesm2022/nx-ddd-firestore-adapters-firebase.mjs} +20 -13
- package/fesm2022/nx-ddd-firestore-adapters-firebase.mjs.map +1 -0
- package/fesm2022/nx-ddd-firestore.mjs +796 -0
- package/fesm2022/nx-ddd-firestore.mjs.map +1 -0
- package/index.d.ts +424 -7
- package/package.json +26 -6
- package/README.md +0 -172
- package/adapters/admin/admin.adapter.d.ts +0 -36
- package/adapters/admin/admin.adapter.js.map +0 -1
- package/adapters/admin/index.js +0 -2
- package/adapters/admin/index.js.map +0 -1
- package/adapters/base/base.adapter.d.ts +0 -35
- package/adapters/base/base.adapter.js +0 -189
- package/adapters/base/base.adapter.js.map +0 -1
- package/adapters/base/index.d.ts +0 -1
- package/adapters/base/index.js +0 -2
- package/adapters/base/index.js.map +0 -1
- package/adapters/dayjs/dayjs.adatper.d.ts +0 -15
- package/adapters/dayjs/dayjs.adatper.js +0 -44
- package/adapters/dayjs/dayjs.adatper.js.map +0 -1
- package/adapters/dayjs/index.d.ts +0 -1
- package/adapters/dayjs/index.js +0 -2
- package/adapters/dayjs/index.js.map +0 -1
- package/adapters/firebase/firebase.adapter.d.ts +0 -32
- package/adapters/firebase/firebase.adapter.js.map +0 -1
- package/adapters/firebase/index.js +0 -2
- package/adapters/firebase/index.js.map +0 -1
- package/adapters/index.d.ts +0 -1
- package/adapters/index.js +0 -2
- package/adapters/index.js.map +0 -1
- package/converter/converter.d.ts +0 -17
- package/converter/converter.js +0 -31
- package/converter/converter.js.map +0 -1
- package/converter/index.d.ts +0 -1
- package/converter/index.js +0 -2
- package/converter/index.js.map +0 -1
- package/dao/firestore.dao.d.ts +0 -17
- package/dao/firestore.dao.js +0 -22
- package/dao/firestore.dao.js.map +0 -1
- package/dao/index.d.ts +0 -1
- package/dao/index.js +0 -2
- package/dao/index.js.map +0 -1
- package/decorators/decorators.d.ts +0 -87
- package/decorators/decorators.js +0 -36
- package/decorators/decorators.js.map +0 -1
- package/decorators/index.d.ts +0 -1
- package/decorators/index.js +0 -2
- package/decorators/index.js.map +0 -1
- package/index.js +0 -8
- package/index.js.map +0 -1
- package/interfaces/index.d.ts +0 -1
- package/interfaces/index.js +0 -2
- package/interfaces/index.js.map +0 -1
- package/interfaces/interfaces.d.ts +0 -63
- package/interfaces/interfaces.js +0 -2
- package/interfaces/interfaces.js.map +0 -1
- package/path-builder/index.d.ts +0 -1
- package/path-builder/index.js +0 -2
- package/path-builder/index.js.map +0 -1
- package/path-builder/path-builder.d.ts +0 -34
- package/path-builder/path-builder.js +0 -33
- package/path-builder/path-builder.js.map +0 -1
- package/query/firestore.query.d.ts +0 -33
- package/query/firestore.query.js +0 -75
- package/query/firestore.query.js.map +0 -1
- package/query/index.d.ts +0 -1
- package/query/index.js +0 -2
- package/query/index.js.map +0 -1
- package/query/v2/cached-query.d.ts +0 -58
- package/query/v2/cached-query.js +0 -102
- package/query/v2/cached-query.js.map +0 -1
- package/query/v2/index.d.ts +0 -2
- package/query/v2/index.js +0 -3
- package/query/v2/index.js.map +0 -1
- package/query/v2/query.d.ts +0 -46
- package/query/v2/query.js +0 -81
- package/query/v2/query.js.map +0 -1
- package/repository/index.d.ts +0 -1
- package/repository/index.js +0 -2
- package/repository/index.js.map +0 -1
- package/repository/repository.d.ts +0 -65
- package/repository/repository.js +0 -218
- package/repository/repository.js.map +0 -1
- package/testing/common.d.ts +0 -7
- package/testing/common.js +0 -19
- package/testing/common.js.map +0 -1
- package/testing/index.d.ts +0 -1
- package/testing/index.js +0 -2
- package/testing/index.js.map +0 -1
package/index.d.ts
CHANGED
|
@@ -1,7 +1,424 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { QueryDocumentSnapshot } from 'firebase-admin/firestore';
|
|
2
|
+
import { Observable, ReplaySubject } from 'rxjs';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import * as dayjs from 'dayjs';
|
|
5
|
+
import dayjs__default from 'dayjs';
|
|
6
|
+
import Dexie from 'dexie';
|
|
7
|
+
import { Repository } from '@nx-ddd/common/domain';
|
|
8
|
+
|
|
9
|
+
type DocumentData = {
|
|
10
|
+
[field: string]: any;
|
|
11
|
+
};
|
|
12
|
+
interface GetOptions {
|
|
13
|
+
readonly source?: 'default' | 'server' | 'cache';
|
|
14
|
+
}
|
|
15
|
+
interface DocumentChangeAction<T> {
|
|
16
|
+
type: any;
|
|
17
|
+
payload: {
|
|
18
|
+
doc: DocumentSnapshot<T>;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
interface DocumentSnapshot<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData> {
|
|
22
|
+
id: string;
|
|
23
|
+
ref: {
|
|
24
|
+
path: string;
|
|
25
|
+
};
|
|
26
|
+
data: () => AppModelType | undefined;
|
|
27
|
+
get: (fieldPath: string) => any;
|
|
28
|
+
exists?: (() => boolean) | boolean;
|
|
29
|
+
}
|
|
30
|
+
interface QuerySnapshot<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData> {
|
|
31
|
+
docs: Array<QueryDocumentSnapshot<AppModelType, DbModelType>>;
|
|
32
|
+
}
|
|
33
|
+
interface Timestamp {
|
|
34
|
+
readonly seconds: number;
|
|
35
|
+
readonly nanoseconds: number;
|
|
36
|
+
toDate(): Date;
|
|
37
|
+
toMillis(): number;
|
|
38
|
+
isEqual(other: Timestamp): boolean;
|
|
39
|
+
valueOf(): string;
|
|
40
|
+
}
|
|
41
|
+
interface TimestampConstructor {
|
|
42
|
+
new (seconds: number, nanoseconds: number): Timestamp;
|
|
43
|
+
now(): Timestamp;
|
|
44
|
+
fromDate(date: Date): Timestamp;
|
|
45
|
+
fromMillis(milliseconds: number): Timestamp;
|
|
46
|
+
}
|
|
47
|
+
type FieldValue = any;
|
|
48
|
+
type ToFirestoreData<Entity, Date> = {
|
|
49
|
+
[K in keyof Entity]: Entity[K] extends Date ? Timestamp | FieldValue : Entity[K];
|
|
50
|
+
};
|
|
51
|
+
interface DocumentReference<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, Origin = any> {
|
|
52
|
+
__ref?: Origin;
|
|
53
|
+
exists(): Promise<boolean>;
|
|
54
|
+
set(data: AppModelType, options?: any): Promise<void | any>;
|
|
55
|
+
get(): Promise<DocumentSnapshot<AppModelType, DbModelType>>;
|
|
56
|
+
update(data: AppModelType): Promise<void | any>;
|
|
57
|
+
delete(): Promise<void | any>;
|
|
58
|
+
stateChanges?: () => Observable<DocumentSnapshot<AppModelType, DbModelType>>;
|
|
59
|
+
}
|
|
60
|
+
type CollectionReference<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, Origin = any> = Query<AppModelType, DbModelType, Origin>;
|
|
61
|
+
type CollectionGroup<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, Origin = any> = Query<AppModelType, DbModelType, Origin>;
|
|
62
|
+
interface Query<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, Origin = any> {
|
|
63
|
+
__ref?: Origin;
|
|
64
|
+
stateChanges?: () => Observable<DocumentChangeAction<DocumentData>[]>;
|
|
65
|
+
get(options?: GetOptions): Promise<QuerySnapshot<AppModelType, DbModelType>>;
|
|
66
|
+
onSnapshot?(onNext: (snapshot: QuerySnapshot<AppModelType, DbModelType>) => void, onError?: (error: Error) => void): () => void;
|
|
67
|
+
count(): Promise<number>;
|
|
68
|
+
}
|
|
69
|
+
type CollectionLike<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData, Origin = any> = CollectionReference<AppModelType, DbModelType, Origin> | CollectionGroup<AppModelType, DbModelType, Origin> | Query<AppModelType, DbModelType, Origin>;
|
|
70
|
+
|
|
71
|
+
declare class DateAdapter {
|
|
72
|
+
isDate<D>(value: any): value is D;
|
|
73
|
+
isValid(value: any): boolean;
|
|
74
|
+
getJsDate<D>(value: any): D;
|
|
75
|
+
convertToDate<D>(value: Date): D;
|
|
76
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DateAdapter, never>;
|
|
77
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<DateAdapter>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type QueryFn<AppModelType, DbModelType, R> = (collection?: any) => R;
|
|
81
|
+
type WhereFilterOp = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any' | 'not-in';
|
|
82
|
+
declare abstract class FirestoreAdapter<Date = any> {
|
|
83
|
+
protected dateAdapter: DateAdapter;
|
|
84
|
+
protected abstract isTimestamp(v: any): v is Timestamp;
|
|
85
|
+
protected abstract isFieldValue(v: any): v is FieldValue;
|
|
86
|
+
abstract get Timestamp(): any;
|
|
87
|
+
abstract get FieldValue(): any;
|
|
88
|
+
abstract get FieldPath(): any;
|
|
89
|
+
abstract doc<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(path: string): DocumentReference<AppModelType>;
|
|
90
|
+
abstract collection<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(path: string): CollectionReference<AppModelType, DbModelType>;
|
|
91
|
+
abstract collectionGroup<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(collectionId: string): CollectionGroup<AppModelType, DbModelType>;
|
|
92
|
+
abstract query<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(collection: CollectionReference<AppModelType, DbModelType>, ...queryFnArray: QueryFn<AppModelType, DbModelType, any>[]): Query<AppModelType, DbModelType>;
|
|
93
|
+
abstract where<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(key: string, evaluation: WhereFilterOp, value: unknown): QueryFn<AppModelType, DbModelType, any>;
|
|
94
|
+
abstract orderBy<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(key: string, order: 'asc' | 'desc'): QueryFn<AppModelType, DbModelType, any>;
|
|
95
|
+
abstract limit<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(n: number): QueryFn<AppModelType, DbModelType, any>;
|
|
96
|
+
abstract runTransaction(fn: any): any;
|
|
97
|
+
abstract batch(): any;
|
|
98
|
+
toFirestoreData<Entity>(entity: Entity): ToFirestoreData<Entity, Date>;
|
|
99
|
+
fromFirestoreData<Entity>(data: ToFirestoreData<Entity, Date>): Entity;
|
|
100
|
+
toFirestore<T>(obj: object, Entity: new () => T): object;
|
|
101
|
+
fromFirestore<T = any>(data: any, Entity: new () => T): T;
|
|
102
|
+
/**
|
|
103
|
+
* @description FirestoreのUpdateは通常のオブジェクトでは孫以下のプロパティが既存データとマージされないので、パスに変換する必要がある。
|
|
104
|
+
*/
|
|
105
|
+
flattenForUpdate(obj: any): any;
|
|
106
|
+
convertDateToTimestamp(date: Date): Timestamp;
|
|
107
|
+
convertTimestampToDate(timestamp: Timestamp): Date;
|
|
108
|
+
}
|
|
109
|
+
declare function provideFirestoreAdapter(useClass: new () => FirestoreAdapter): {
|
|
110
|
+
provide: typeof FirestoreAdapter;
|
|
111
|
+
useClass: new () => FirestoreAdapter;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
interface IFirestoreConverter<E extends {
|
|
115
|
+
id: string;
|
|
116
|
+
}> {
|
|
117
|
+
fromFirestore(doc: DocumentSnapshot<object>): E;
|
|
118
|
+
fromFirestoreMany(docs: DocumentSnapshot<object>[]): E[];
|
|
119
|
+
toFirestore(entity: Partial<E>): object;
|
|
120
|
+
fromObject?(obj: object): E;
|
|
121
|
+
toObject?(entity: E): object;
|
|
122
|
+
}
|
|
123
|
+
declare function getConverter<Entity extends {
|
|
124
|
+
id: string;
|
|
125
|
+
}>(Entity: new () => Entity, adapter?: FirestoreAdapter): IFirestoreConverter<Entity>;
|
|
126
|
+
declare function injectConverter<Entity extends {
|
|
127
|
+
id: string;
|
|
128
|
+
}>(Entity: new () => Entity): IFirestoreConverter<Entity>;
|
|
129
|
+
|
|
130
|
+
type CollectionParamMap<Entity extends {
|
|
131
|
+
id: string;
|
|
132
|
+
}> = Partial<Entity>;
|
|
133
|
+
type DocParamMap<Entity extends {
|
|
134
|
+
id: string;
|
|
135
|
+
}> = CollectionParamMap<Entity> & Pick<Entity, 'id'>;
|
|
136
|
+
type ExtractParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
|
|
137
|
+
[K in Param | keyof ExtractParams<Rest>]: string;
|
|
138
|
+
} : T extends `${infer _Start}:${infer Param}` ? {
|
|
139
|
+
[K in Param]: string;
|
|
140
|
+
} : {};
|
|
141
|
+
type ColParam$3<T extends {
|
|
142
|
+
readonly collectionPath: string;
|
|
143
|
+
}> = Omit<ExtractParams<T['collectionPath']>, 'id'>;
|
|
144
|
+
type DocParam$2<T extends {
|
|
145
|
+
readonly collectionPath: string;
|
|
146
|
+
}> = ColParam$3<T> & {
|
|
147
|
+
id: string;
|
|
148
|
+
};
|
|
149
|
+
declare class FirestorePathBuilder<Entity extends {
|
|
150
|
+
id: string;
|
|
151
|
+
}, Path extends string = string> {
|
|
152
|
+
private paths;
|
|
153
|
+
doc(param: DocParamMap<Entity>): string;
|
|
154
|
+
collection(param?: Omit<ExtractParams<Path>, 'id'> | {}): string;
|
|
155
|
+
collectionGroup(): string;
|
|
156
|
+
constructor(paths: string[]);
|
|
157
|
+
}
|
|
158
|
+
declare function pathBuilderFactory<E extends {
|
|
159
|
+
id: string;
|
|
160
|
+
}, Path extends string = string>(path: Path): FirestorePathBuilder<E, Path>;
|
|
161
|
+
declare function parsePath<Path extends string = string>(path: Path): string[];
|
|
162
|
+
declare const resolvePaths: (obj: object, paths: string[]) => string;
|
|
163
|
+
|
|
164
|
+
declare class FirestoreDAO<Entity extends {
|
|
165
|
+
id: string;
|
|
166
|
+
}, FirestoreData = ToFirestoreData<Entity, dayjs__default.Dayjs>> {
|
|
167
|
+
protected adapter: FirestoreAdapter;
|
|
168
|
+
protected pathBuilder: FirestorePathBuilder<Entity>;
|
|
169
|
+
constructor(adapter: FirestoreAdapter, pathBuilder: FirestorePathBuilder<Entity>);
|
|
170
|
+
collection(paramMap?: Partial<Entity>): CollectionReference<FirestoreData>;
|
|
171
|
+
collectionGroup(): CollectionGroup<FirestoreData>;
|
|
172
|
+
doc(paramMap: Partial<Entity> & {
|
|
173
|
+
id: string;
|
|
174
|
+
}): DocumentReference<FirestoreData>;
|
|
175
|
+
getCollection(paramMap?: Partial<Entity>): CollectionLike;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
declare const FIRESTORE_ANNOTATIONS = "firestore_annotations";
|
|
179
|
+
type FirestoreFieldType = 'id' | 'boolean' | 'number' | 'timestamp' | 'string' | 'geopoint' | 'null' | 'map' | 'array' | 'reference';
|
|
180
|
+
interface FirestoreAnnotation {
|
|
181
|
+
type: FirestoreFieldType;
|
|
182
|
+
fieldName: string;
|
|
183
|
+
propName: string;
|
|
184
|
+
childType: any;
|
|
185
|
+
}
|
|
186
|
+
declare const createDecorator: (type: FirestoreFieldType, options?: {
|
|
187
|
+
childType?: any;
|
|
188
|
+
}) => (nameOrProps?: {
|
|
189
|
+
name?: string;
|
|
190
|
+
} | string) => (target: any, propName: string) => void;
|
|
191
|
+
declare const createPropsDecorator: (type: FirestoreFieldType, options?: {
|
|
192
|
+
childType?: any;
|
|
193
|
+
}) => (nameOrProps?: {
|
|
194
|
+
name?: string;
|
|
195
|
+
} | string) => (target: any, propName: string) => void;
|
|
196
|
+
declare const createClassDecorator: <Props extends {
|
|
197
|
+
name: string;
|
|
198
|
+
}>(type: string) => (nameOrProps: Props | string) => (target: any) => void;
|
|
199
|
+
declare const getAnnotations: (target: any) => FirestoreAnnotation[];
|
|
200
|
+
/** @deprecated use getAnnotations */
|
|
201
|
+
declare function getFirestoreAnnotations(target: any): FirestoreAnnotation[];
|
|
202
|
+
declare function getCollection(target: any): string;
|
|
203
|
+
declare const Firestore: {
|
|
204
|
+
Collection: (nameOrProps: string | {
|
|
205
|
+
name: string;
|
|
206
|
+
}) => (target: any) => void;
|
|
207
|
+
ID: (nameOrProps?: {
|
|
208
|
+
name?: string;
|
|
209
|
+
} | string) => (target: any, propName: string) => void;
|
|
210
|
+
String: (nameOrProps?: {
|
|
211
|
+
name?: string;
|
|
212
|
+
} | string) => (target: any, propName: string) => void;
|
|
213
|
+
Null: (nameOrProps?: {
|
|
214
|
+
name?: string;
|
|
215
|
+
} | string) => (target: any, propName: string) => void;
|
|
216
|
+
Geopoint: (nameOrProps?: {
|
|
217
|
+
name?: string;
|
|
218
|
+
} | string) => (target: any, propName: string) => void;
|
|
219
|
+
Boolean: (nameOrProps?: {
|
|
220
|
+
name?: string;
|
|
221
|
+
} | string) => (target: any, propName: string) => void;
|
|
222
|
+
Timestamp: (nameOrProps?: {
|
|
223
|
+
name?: string;
|
|
224
|
+
} | string) => (target: any, propName: string) => void;
|
|
225
|
+
Number: (nameOrProps?: {
|
|
226
|
+
name?: string;
|
|
227
|
+
} | string) => (target: any, propName: string) => void;
|
|
228
|
+
Map: (childType?: () => any, props?: {
|
|
229
|
+
name?: string;
|
|
230
|
+
}) => (target: any, propName: string) => void;
|
|
231
|
+
Array: (childType?: () => any, props?: {
|
|
232
|
+
name?: string;
|
|
233
|
+
}) => (target: any, propName: string) => void;
|
|
234
|
+
Reference: (nameOrProps?: {
|
|
235
|
+
name?: string;
|
|
236
|
+
} | string) => (target: any, propName: string) => void;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
declare class FirestoreQuery$1<Entity extends {
|
|
240
|
+
id: string;
|
|
241
|
+
} = any, FirestoreData = ToFirestoreData<Entity, dayjs__default.Dayjs>> extends FirestoreDAO<Entity, FirestoreData> {
|
|
242
|
+
protected converter: IFirestoreConverter<Entity>;
|
|
243
|
+
protected pathBuilder: FirestorePathBuilder<Entity>;
|
|
244
|
+
constructor(adapter: FirestoreAdapter, converter: IFirestoreConverter<Entity>, pathBuilder: FirestorePathBuilder<Entity>);
|
|
245
|
+
protected readonly collection$: ReplaySubject<CollectionLike<FirestoreData>>;
|
|
246
|
+
protected readonly list$: Observable<Entity[]>;
|
|
247
|
+
/** @deprecated */
|
|
248
|
+
listChanges(paramMap?: Partial<Entity>, options?: {
|
|
249
|
+
switch?: boolean;
|
|
250
|
+
}): Observable<Entity[]>;
|
|
251
|
+
listChangesV2(paramMap?: Partial<Entity>): Observable<Entity[]>;
|
|
252
|
+
listChangesAfter(updatedAt: dayjs__default.Dayjs, { limit }?: {
|
|
253
|
+
limit?: number;
|
|
254
|
+
}): Observable<Entity[]>;
|
|
255
|
+
changes({ id }: Partial<Entity>): Observable<Entity>;
|
|
256
|
+
changesV2(params: Partial<Entity>): Observable<Entity>;
|
|
257
|
+
get({ id }: Partial<Entity> & {
|
|
258
|
+
id: string;
|
|
259
|
+
}): Promise<Entity>;
|
|
260
|
+
list(paramMap?: Partial<Entity>): Promise<Entity[]>;
|
|
261
|
+
protected listChangesByCollectionRef(collection: CollectionReference<FirestoreData> | CollectionGroup<FirestoreData>): Observable<Entity[]>;
|
|
262
|
+
protected switchCollectionRef(paramMap?: Partial<Entity>): void;
|
|
263
|
+
switchCollection(collection: CollectionLike<any>): void;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
type ColParam$2<T extends BaseFirestoreQuery<any>> = Omit<ExtractParams<T['collectionPath']>, 'id'>;
|
|
267
|
+
type DocParam$1<T extends BaseFirestoreQuery<any>> = ColParam$2<T> & {
|
|
268
|
+
id: string;
|
|
269
|
+
};
|
|
270
|
+
declare abstract class BaseFirestoreQuery<Entity extends {
|
|
271
|
+
id: string;
|
|
272
|
+
} = any> {
|
|
273
|
+
protected abstract readonly adapter: FirestoreAdapter;
|
|
274
|
+
protected abstract readonly converter: IFirestoreConverter<Entity>;
|
|
275
|
+
abstract readonly collectionPath: string;
|
|
276
|
+
protected abstract pathBuilder: FirestorePathBuilder<Entity, typeof this.collectionPath>;
|
|
277
|
+
protected abstract dao: FirestoreDAO<Entity>;
|
|
278
|
+
count(paramMap?: ColParam$2<this>): Promise<number>;
|
|
279
|
+
changes(params: DocParam$1<this>): Observable<Entity>;
|
|
280
|
+
get(paramMap: DocParam$1<this>): Promise<Entity>;
|
|
281
|
+
list(paramMap?: ColParam$2<this>): Promise<Entity[]>;
|
|
282
|
+
listChanges(paramMap?: ColParam$2<this>): Observable<Entity[]>;
|
|
283
|
+
protected getChanges$ByDocument(doc: DocumentReference): Observable<Entity>;
|
|
284
|
+
protected getListChanges$ByCollectionLike(collection: CollectionLike): Observable<Entity[]>;
|
|
285
|
+
}
|
|
286
|
+
declare abstract class FirestoreQuery<Entity extends {
|
|
287
|
+
id: string;
|
|
288
|
+
} = any> extends BaseFirestoreQuery<Entity> {
|
|
289
|
+
protected readonly adapter: FirestoreAdapter<any>;
|
|
290
|
+
abstract readonly collectionPath: string;
|
|
291
|
+
protected abstract readonly converter: IFirestoreConverter<Entity>;
|
|
292
|
+
get pathBuilder(): FirestorePathBuilder<Entity, typeof this.collectionPath>;
|
|
293
|
+
protected get dao(): FirestoreDAO<Entity, ToFirestoreData<Entity, dayjs.Dayjs>>;
|
|
294
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<FirestoreQuery<any>, never>;
|
|
295
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<FirestoreQuery<any>>;
|
|
296
|
+
}
|
|
297
|
+
declare function getFirestoreQuery<Entity extends {
|
|
298
|
+
id: string;
|
|
299
|
+
}>(entity: {
|
|
300
|
+
new (): Entity;
|
|
301
|
+
}, adapter?: FirestoreAdapter): BaseFirestoreQuery<Entity>;
|
|
302
|
+
declare function injectFirestoreQuery<Entity extends {
|
|
303
|
+
id: string;
|
|
304
|
+
}>(entity: {
|
|
305
|
+
new (): Entity;
|
|
306
|
+
}): BaseFirestoreQuery<Entity>;
|
|
307
|
+
|
|
308
|
+
type ColParam$1<T extends {
|
|
309
|
+
readonly collectionPath: string;
|
|
310
|
+
}> = Omit<ExtractParams<T['collectionPath']>, 'id'>;
|
|
311
|
+
interface EntityData {
|
|
312
|
+
id: string;
|
|
313
|
+
value: string;
|
|
314
|
+
collectionPath: string;
|
|
315
|
+
updatedAt: string;
|
|
316
|
+
}
|
|
317
|
+
declare class DexieAdapter<E extends {
|
|
318
|
+
id: string;
|
|
319
|
+
updatedAt: dayjs__default.Dayjs;
|
|
320
|
+
}> extends Dexie {
|
|
321
|
+
entities: Dexie.Table<EntityData, string>;
|
|
322
|
+
constructor();
|
|
323
|
+
count$(): Observable<number>;
|
|
324
|
+
getLastUpdatedAt$(collectionPath: string): Observable<dayjs__default.Dayjs>;
|
|
325
|
+
bulkPut(collectionPath: string, entities: E[]): Promise<string>;
|
|
326
|
+
listChanges(collectionPath: string): Observable<E[]>;
|
|
327
|
+
}
|
|
328
|
+
declare class FirestoreIndexedDbCached<E extends {
|
|
329
|
+
id: string;
|
|
330
|
+
updatedAt: dayjs__default.Dayjs;
|
|
331
|
+
}> {
|
|
332
|
+
protected collectionPath: string;
|
|
333
|
+
constructor(collectionPath: string);
|
|
334
|
+
readonly adapter: DexieAdapter<E>;
|
|
335
|
+
getLastUpdatedAt$(): Observable<dayjs__default.Dayjs>;
|
|
336
|
+
setMany(entities: E[]): Promise<string>;
|
|
337
|
+
listChanges(): Observable<E[]>;
|
|
338
|
+
}
|
|
339
|
+
declare abstract class CachedFirestoreQuery<E extends {
|
|
340
|
+
id: string;
|
|
341
|
+
updatedAt: dayjs__default.Dayjs;
|
|
342
|
+
} = any> extends FirestoreQuery<E> {
|
|
343
|
+
protected _cached: FirestoreIndexedDbCached<E>;
|
|
344
|
+
protected get cached(): FirestoreIndexedDbCached<E>;
|
|
345
|
+
protected readonly config: {
|
|
346
|
+
throttleTime: number;
|
|
347
|
+
loadChunkSize: number;
|
|
348
|
+
};
|
|
349
|
+
listChanges(paramMap?: ColParam$1<this>): Observable<E[]>;
|
|
350
|
+
protected _listChange(paramMap?: ColParam$1<this>): Observable<E[]>;
|
|
351
|
+
protected _listChangesAfter(collection: CollectionLike, updatedAt: dayjs__default.Dayjs, { limit }?: {
|
|
352
|
+
limit?: number;
|
|
353
|
+
}): Observable<E[]>;
|
|
354
|
+
progressChanges(): Observable<{
|
|
355
|
+
cloud: number;
|
|
356
|
+
local: number;
|
|
357
|
+
}>;
|
|
358
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<CachedFirestoreQuery<any>, never>;
|
|
359
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<CachedFirestoreQuery<any>>;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
type ExtractEntity<T extends BaseFirestoreRepository<any, any>> = T extends BaseFirestoreRepository<infer Entity, any> ? Entity : never;
|
|
363
|
+
type ColParam<T extends BaseFirestoreRepository<any, any>> = Omit<ExtractParams<T['collectionPath']>, 'id'>;
|
|
364
|
+
type DocParam<T extends BaseFirestoreRepository<any, any>, TExtra = {}> = ColParam<T> & {
|
|
365
|
+
id: string;
|
|
366
|
+
} & TExtra;
|
|
367
|
+
declare abstract class BaseFirestoreRepository<Entity extends {
|
|
368
|
+
id: string;
|
|
369
|
+
}, TExtraParams = {}> extends Repository<Entity> {
|
|
370
|
+
abstract readonly collectionPath: string;
|
|
371
|
+
protected abstract readonly adapter: FirestoreAdapter;
|
|
372
|
+
protected abstract converter: IFirestoreConverter<Entity>;
|
|
373
|
+
abstract readonly pathBuilder: FirestorePathBuilder<Entity, typeof this.collectionPath>;
|
|
374
|
+
list(paramMap?: ColParam<this>, query?: any): Promise<Entity[]>;
|
|
375
|
+
listChanges(): Observable<Entity[]>;
|
|
376
|
+
count(paramMap?: ColParam<this>): Promise<number>;
|
|
377
|
+
get(paramMap?: DocParam<this, TExtraParams>): Promise<Entity>;
|
|
378
|
+
save(entity: DocParam<this, TExtraParams> & Entity): Promise<[Entity, boolean]>;
|
|
379
|
+
saveMany(entities: Entity[]): Promise<void>;
|
|
380
|
+
create(entity: DocParam<this, TExtraParams> & Entity): Promise<Entity>;
|
|
381
|
+
createMany(entities: (DocParam<this, TExtraParams> & Entity)[]): Promise<Entity[]>;
|
|
382
|
+
update(entity: DocParam<this, TExtraParams> & Partial<Entity>): Promise<void>;
|
|
383
|
+
updateMany(data: Partial<Entity>[]): Promise<void>;
|
|
384
|
+
delete(paramMap: DocParam<this, TExtraParams>): Promise<void>;
|
|
385
|
+
deleteMany(params: {
|
|
386
|
+
id: string;
|
|
387
|
+
}[]): Promise<number>;
|
|
388
|
+
deleteAll(): Promise<void>;
|
|
389
|
+
bulkWrite(entities: (DocParam<this, TExtraParams> & Entity)[], timestamps?: string[]): Promise<void>;
|
|
390
|
+
bulkCreate(entities: (DocParam<this, TExtraParams> & Entity)[]): Promise<void>;
|
|
391
|
+
bulkUpdate(entities: (DocParam<this, TExtraParams> & Partial<Entity>)[]): Promise<void>;
|
|
392
|
+
bulkDelete(paramMaps: DocParam<this, TExtraParams>[]): Promise<void>;
|
|
393
|
+
protected collection(paramMap?: Omit<ExtractParams<typeof this.collectionPath>, 'id'>): CollectionReference<object>;
|
|
394
|
+
protected collectionGroup(): CollectionGroup<object>;
|
|
395
|
+
protected doc(paramMap: DocParam<this, TExtraParams>): DocumentReference<object>;
|
|
396
|
+
protected genId: () => string;
|
|
397
|
+
protected _list(collection: CollectionReference<object>): Promise<Entity[]>;
|
|
398
|
+
protected _get(doc: DocumentReference<object>): Promise<Entity>;
|
|
399
|
+
protected _save(doc: DocumentReference<object>, entity: Entity): Promise<[Entity, boolean]>;
|
|
400
|
+
protected _create(doc: DocumentReference<object>, entity: Entity): Promise<Entity>;
|
|
401
|
+
protected _set(doc: DocumentReference<object>, entity: Partial<Entity>, isUpdate?: boolean): Promise<DocumentSnapshot<object, DocumentData>>;
|
|
402
|
+
protected buildServerTimestampObject(keys?: string[]): {};
|
|
403
|
+
}
|
|
404
|
+
declare abstract class FirestoreRepository<Entity extends {
|
|
405
|
+
id: string;
|
|
406
|
+
}, TExtraParams = {}> extends BaseFirestoreRepository<Entity, TExtraParams> {
|
|
407
|
+
protected readonly adapter: FirestoreAdapter<any>;
|
|
408
|
+
get pathBuilder(): FirestorePathBuilder<Entity, typeof this.collectionPath>;
|
|
409
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<FirestoreRepository<any, any>, never>;
|
|
410
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<FirestoreRepository<any, any>>;
|
|
411
|
+
}
|
|
412
|
+
declare function getFirestoreRepository<Entity extends {
|
|
413
|
+
id: string;
|
|
414
|
+
}, TExtraParams = {}>(entity: {
|
|
415
|
+
new (): Entity;
|
|
416
|
+
}, adapter?: FirestoreAdapter): BaseFirestoreRepository<Entity, TExtraParams>;
|
|
417
|
+
declare function injectFirestoreRepository<Entity extends {
|
|
418
|
+
id: string;
|
|
419
|
+
}, TExtraParams = {}>(entity: {
|
|
420
|
+
new (): Entity;
|
|
421
|
+
}): BaseFirestoreRepository<Entity, TExtraParams>;
|
|
422
|
+
|
|
423
|
+
export { BaseFirestoreQuery, BaseFirestoreRepository, CachedFirestoreQuery, FIRESTORE_ANNOTATIONS, Firestore, FirestoreAdapter, FirestoreDAO, FirestorePathBuilder, FirestoreQuery$1 as FirestoreQuery, FirestoreQuery as FirestoreQueryV2, FirestoreRepository, createClassDecorator, createDecorator, createPropsDecorator, getAnnotations, getCollection, getConverter, getFirestoreAnnotations, getFirestoreQuery, getFirestoreRepository, injectConverter, injectFirestoreQuery, injectFirestoreRepository, parsePath, pathBuilderFactory, provideFirestoreAdapter, resolvePaths };
|
|
424
|
+
export type { ColParam$3 as ColParam, CollectionGroup, CollectionLike, CollectionReference, DocParam$2 as DocParam, DocumentChangeAction, DocumentData, DocumentReference, DocumentSnapshot, ExtractEntity, ExtractParams, FieldValue, FirestoreAnnotation, FirestoreFieldType, GetOptions, IFirestoreConverter, Query, QueryFn, QuerySnapshot, Timestamp, TimestampConstructor, ToFirestoreData, WhereFilterOp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx-ddd/firestore",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.3.1",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"homepage": "https://github.com/xx-machina/plaform/tree/main/packages/@nx-ddd/firestore",
|
|
@@ -9,10 +9,30 @@
|
|
|
9
9
|
"url": "https://github.com/xx-machina/plaform.git"
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"@nx-ddd/common": "19.
|
|
13
|
-
"@nx-ddd/core": "19.
|
|
12
|
+
"@nx-ddd/common": "19.3.1",
|
|
13
|
+
"@nx-ddd/core": "19.3.1"
|
|
14
14
|
},
|
|
15
|
-
"dependencies": {
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"tslib": "^2.3.0"
|
|
17
|
+
},
|
|
18
|
+
"module": "fesm2022/nx-ddd-firestore.mjs",
|
|
19
|
+
"typings": "index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
"./package.json": {
|
|
22
|
+
"default": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./index.d.ts",
|
|
26
|
+
"default": "./fesm2022/nx-ddd-firestore.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./adapters/admin": {
|
|
29
|
+
"types": "./adapters/admin/index.d.ts",
|
|
30
|
+
"default": "./fesm2022/nx-ddd-firestore-adapters-admin.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./adapters/firebase": {
|
|
33
|
+
"types": "./adapters/firebase/index.d.ts",
|
|
34
|
+
"default": "./fesm2022/nx-ddd-firestore-adapters-firebase.mjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"sideEffects": false
|
|
18
38
|
}
|
package/README.md
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
# @nx-ddd/firestore
|
|
2
|
-
|
|
3
|
-
A Firestore adapter for @nx-ddd/core that provides seamless integration with Firebase Cloud Firestore.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @nx-ddd/firestore
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Features
|
|
12
|
-
|
|
13
|
-
### 1. Repository Implementation
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
import { FirestoreRepository } from '@nx-ddd/firestore';
|
|
17
|
-
|
|
18
|
-
@Injectable()
|
|
19
|
-
export class UserFirestoreRepository extends FirestoreRepository<User> implements UserRepository {
|
|
20
|
-
constructor(firestore: Firestore) {
|
|
21
|
-
super(firestore, 'users');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async findByEmail(email: string): Promise<User | null> {
|
|
25
|
-
const snapshot = await this.collection
|
|
26
|
-
.where('email', '==', email)
|
|
27
|
-
.limit(1)
|
|
28
|
-
.get();
|
|
29
|
-
|
|
30
|
-
return this.toEntity(snapshot.docs[0]);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### 2. Entity Mapping
|
|
36
|
-
|
|
37
|
-
```typescript
|
|
38
|
-
import { FirestoreEntity } from '@nx-ddd/firestore';
|
|
39
|
-
|
|
40
|
-
@FirestoreEntity({
|
|
41
|
-
collection: 'users',
|
|
42
|
-
converters: {
|
|
43
|
-
createdAt: FirestoreTimestampConverter,
|
|
44
|
-
updatedAt: FirestoreTimestampConverter
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
export class User extends Entity {
|
|
48
|
-
constructor(
|
|
49
|
-
id: ID,
|
|
50
|
-
public readonly email: string,
|
|
51
|
-
public readonly name: string,
|
|
52
|
-
public readonly createdAt: Date,
|
|
53
|
-
public readonly updatedAt: Date
|
|
54
|
-
) {
|
|
55
|
-
super(id);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### 3. Transaction Support
|
|
61
|
-
|
|
62
|
-
```typescript
|
|
63
|
-
import { FirestoreTransactional } from '@nx-ddd/firestore';
|
|
64
|
-
|
|
65
|
-
@Injectable()
|
|
66
|
-
export class UserService {
|
|
67
|
-
constructor(private readonly firestore: Firestore) {}
|
|
68
|
-
|
|
69
|
-
@FirestoreTransactional()
|
|
70
|
-
async createUserWithProfile(data: UserData): Promise<void> {
|
|
71
|
-
const user = new User(/* ... */);
|
|
72
|
-
const profile = new Profile(/* ... */);
|
|
73
|
-
|
|
74
|
-
await this.userRepository.save(user);
|
|
75
|
-
await this.profileRepository.save(profile);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### 4. Query Building
|
|
81
|
-
|
|
82
|
-
```typescript
|
|
83
|
-
import { FirestoreQueryBuilder } from '@nx-ddd/firestore';
|
|
84
|
-
|
|
85
|
-
@Injectable()
|
|
86
|
-
export class UserQueryService {
|
|
87
|
-
constructor(private readonly builder: FirestoreQueryBuilder) {}
|
|
88
|
-
|
|
89
|
-
async findActiveUsers(): Promise<User[]> {
|
|
90
|
-
return this.builder
|
|
91
|
-
.collection('users')
|
|
92
|
-
.where('status', '==', 'active')
|
|
93
|
-
.orderBy('lastLoginAt', 'desc')
|
|
94
|
-
.limit(10)
|
|
95
|
-
.execute();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## Advanced Features
|
|
101
|
-
|
|
102
|
-
### 1. Batch Operations
|
|
103
|
-
|
|
104
|
-
```typescript
|
|
105
|
-
import { FirestoreBatch } from '@nx-ddd/firestore';
|
|
106
|
-
|
|
107
|
-
@Injectable()
|
|
108
|
-
export class UserBatchService {
|
|
109
|
-
constructor(private readonly batch: FirestoreBatch) {}
|
|
110
|
-
|
|
111
|
-
async deactivateUsers(userIds: string[]): Promise<void> {
|
|
112
|
-
this.batch.begin();
|
|
113
|
-
|
|
114
|
-
for (const id of userIds) {
|
|
115
|
-
this.batch.update(`users/${id}`, { status: 'inactive' });
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
await this.batch.commit();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### 2. Real-time Updates
|
|
124
|
-
|
|
125
|
-
```typescript
|
|
126
|
-
import { FirestoreObservable } from '@nx-ddd/firestore';
|
|
127
|
-
|
|
128
|
-
@Injectable()
|
|
129
|
-
export class UserStreamService {
|
|
130
|
-
constructor(private readonly observable: FirestoreObservable) {}
|
|
131
|
-
|
|
132
|
-
watchUserChanges(userId: string): Observable<User> {
|
|
133
|
-
return this.observable
|
|
134
|
-
.document(`users/${userId}`)
|
|
135
|
-
.valueChanges()
|
|
136
|
-
.pipe(
|
|
137
|
-
map(data => new User(data))
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
### 3. Sub-collections
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
import { FirestoreSubCollection } from '@nx-ddd/firestore';
|
|
147
|
-
|
|
148
|
-
@Injectable()
|
|
149
|
-
export class UserDocumentRepository extends FirestoreRepository<UserDocument> {
|
|
150
|
-
constructor(firestore: Firestore) {
|
|
151
|
-
super(firestore, 'users/:userId/documents');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async findUserDocuments(userId: string): Promise<UserDocument[]> {
|
|
155
|
-
return this.find({ userId });
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
## Best Practices
|
|
161
|
-
|
|
162
|
-
1. Use repository pattern for data access
|
|
163
|
-
2. Implement proper error handling
|
|
164
|
-
3. Use transactions for atomic operations
|
|
165
|
-
4. Leverage batch operations for bulk updates
|
|
166
|
-
5. Consider real-time updates when appropriate
|
|
167
|
-
6. Structure collections and sub-collections carefully
|
|
168
|
-
7. Implement proper security rules
|
|
169
|
-
|
|
170
|
-
## License
|
|
171
|
-
|
|
172
|
-
MIT
|