@nx-ddd/firestore 1.1.0 → 4.20.7
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 +5 -1
- package/adapters/admin/admin.adapter.d.ts +22 -0
- package/adapters/admin/admin.adapter.js +60 -0
- package/adapters/admin/admin.adapter.js.map +1 -0
- package/adapters/admin/index.d.ts +1 -0
- package/adapters/admin/index.js +5 -0
- package/adapters/admin/index.js.map +1 -0
- package/adapters/base/base.adapter.d.ts +20 -0
- package/adapters/base/base.adapter.js +13 -0
- package/adapters/base/base.adapter.js.map +1 -0
- package/adapters/base/index.d.ts +1 -0
- package/adapters/base/index.js +5 -0
- package/adapters/base/index.js.map +1 -0
- package/adapters/firebase/firebase.adapter.d.ts +22 -0
- package/adapters/firebase/firebase.adapter.js +89 -0
- package/adapters/firebase/firebase.adapter.js.map +1 -0
- package/adapters/firebase/index.d.ts +1 -0
- package/adapters/firebase/index.js +5 -0
- package/adapters/firebase/index.js.map +1 -0
- package/adapters/index.d.ts +3 -0
- package/adapters/index.js +7 -0
- package/adapters/index.js.map +1 -0
- package/converter/converter.d.ts +11 -0
- package/converter/converter.js +36 -0
- package/converter/converter.js.map +1 -0
- package/converter/index.d.ts +1 -0
- package/{common/utilities → converter}/index.js +1 -1
- package/converter/index.js.map +1 -0
- package/dao/firestore.dao.d.ts +18 -0
- package/dao/firestore.dao.js +23 -0
- package/dao/firestore.dao.js.map +1 -0
- package/dao/index.d.ts +1 -0
- package/dao/index.js +5 -0
- package/dao/index.js.map +1 -0
- package/decorators/decorators.d.ts +34 -0
- package/decorators/decorators.js +27 -0
- package/decorators/decorators.js.map +1 -0
- package/decorators/index.d.ts +1 -0
- package/decorators/index.js +5 -0
- package/decorators/index.js.map +1 -0
- package/index.d.ts +8 -0
- package/index.js +12 -0
- package/index.js.map +1 -0
- package/interfaces/index.d.ts +1 -0
- package/{admin → interfaces}/index.js +0 -2
- package/interfaces/index.js.map +1 -0
- package/interfaces/interfaces.d.ts +57 -0
- package/interfaces/interfaces.js.map +1 -0
- package/package.json +14 -8
- package/path-builder/index.d.ts +1 -0
- package/path-builder/index.js +5 -0
- package/path-builder/index.js.map +1 -0
- package/path-builder/path-builder.d.ts +21 -0
- package/path-builder/path-builder.js +34 -0
- package/path-builder/path-builder.js.map +1 -0
- package/query/firestore.query.d.ts +26 -0
- package/query/firestore.query.js +50 -0
- package/query/firestore.query.js.map +1 -0
- package/query/index.d.ts +1 -0
- package/query/index.js +5 -0
- package/query/index.js.map +1 -0
- package/repository/decorator.d.ts +8 -0
- package/repository/decorator.js +41 -0
- package/repository/decorator.js.map +1 -0
- package/{nest → repository}/index.d.ts +1 -1
- package/{nest → repository}/index.js +1 -1
- package/repository/index.js.map +1 -0
- package/repository/repository.d.ts +38 -0
- package/repository/repository.js +107 -0
- package/repository/repository.js.map +1 -0
- package/testing/common.d.ts +5 -0
- package/testing/common.js +19 -0
- package/testing/common.js.map +1 -0
- package/testing/domain.d.ts +12 -0
- package/testing/domain.js +22 -0
- package/testing/domain.js.map +1 -0
- package/testing/index.d.ts +3 -0
- package/{client → testing}/index.js +2 -2
- package/testing/index.js.map +1 -0
- package/testing/repository.d.ts +6 -0
- package/testing/repository.js +26 -0
- package/testing/repository.js.map +1 -0
- package/admin/adapter.d.ts +0 -20
- package/admin/adapter.js +0 -62
- package/admin/adapter.js.map +0 -1
- package/admin/index.d.ts +0 -3
- package/admin/index.js.map +0 -1
- package/admin/interfaces.d.ts +0 -8
- package/admin/interfaces.js +0 -3
- package/admin/interfaces.js.map +0 -1
- package/admin/repository.d.ts +0 -9
- package/admin/repository.js +0 -20
- package/admin/repository.js.map +0 -1
- package/client/adapter.d.ts +0 -13
- package/client/adapter.js +0 -35
- package/client/adapter.js.map +0 -1
- package/client/index.d.ts +0 -3
- package/client/index.js.map +0 -1
- package/client/interfaces.d.ts +0 -8
- package/client/interfaces.js +0 -3
- package/client/interfaces.js.map +0 -1
- package/client/repository.d.ts +0 -8
- package/client/repository.js +0 -9
- package/client/repository.js.map +0 -1
- package/common/adapter.d.ts +0 -17
- package/common/adapter.js +0 -24
- package/common/adapter.js.map +0 -1
- package/common/entity.d.ts +0 -26
- package/common/entity.js +0 -30
- package/common/entity.js.map +0 -1
- package/common/index.d.ts +0 -5
- package/common/index.js +0 -9
- package/common/index.js.map +0 -1
- package/common/interfaces.d.ts +0 -51
- package/common/interfaces.js.map +0 -1
- package/common/repository.d.ts +0 -41
- package/common/repository.js +0 -107
- package/common/repository.js.map +0 -1
- package/common/utilities/generate-id.d.ts +0 -1
- package/common/utilities/generate-id.js +0 -22
- package/common/utilities/generate-id.js.map +0 -1
- package/common/utilities/index.d.ts +0 -1
- package/common/utilities/index.js.map +0 -1
- package/nest/adapter.d.ts +0 -21
- package/nest/adapter.js +0 -63
- package/nest/adapter.js.map +0 -1
- package/nest/index.js.map +0 -1
- package/nest/repository.d.ts +0 -9
- package/nest/repository.js +0 -21
- package/nest/repository.js.map +0 -1
- /package/{common → interfaces}/interfaces.js +0 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
export interface GetOptions {
|
|
3
|
+
readonly source?: 'default' | 'server' | 'cache';
|
|
4
|
+
}
|
|
5
|
+
export interface DocumentChangeAction<T> {
|
|
6
|
+
type: any;
|
|
7
|
+
payload: {
|
|
8
|
+
doc: DocumentSnapshot<T>;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface DocumentSnapshot<T> {
|
|
12
|
+
id: string;
|
|
13
|
+
ref: {
|
|
14
|
+
path: string;
|
|
15
|
+
};
|
|
16
|
+
data: () => T;
|
|
17
|
+
}
|
|
18
|
+
export interface QuerySnapshot<T> {
|
|
19
|
+
docs: DocumentSnapshot<T>[];
|
|
20
|
+
}
|
|
21
|
+
export interface Timestamp {
|
|
22
|
+
readonly seconds: number;
|
|
23
|
+
readonly nanoseconds: number;
|
|
24
|
+
toDate(): Date;
|
|
25
|
+
toMillis(): number;
|
|
26
|
+
isEqual(other: Timestamp): boolean;
|
|
27
|
+
valueOf(): string;
|
|
28
|
+
}
|
|
29
|
+
export interface TimestampConstructor {
|
|
30
|
+
new (seconds: number, nanoseconds: number): Timestamp;
|
|
31
|
+
now(): Timestamp;
|
|
32
|
+
fromDate(date: Date): Timestamp;
|
|
33
|
+
fromMillis(milliseconds: number): Timestamp;
|
|
34
|
+
}
|
|
35
|
+
export declare type FieldValue = any;
|
|
36
|
+
export declare type ToFirestoreData<Entity, Date> = {
|
|
37
|
+
[K in keyof Entity]: Entity[K] extends Date ? Timestamp | FieldValue : Entity[K];
|
|
38
|
+
};
|
|
39
|
+
export interface DocumentReference<DocumentData, OriginalReference = any> {
|
|
40
|
+
__ref?: OriginalReference;
|
|
41
|
+
set(data: DocumentData, options?: any): Promise<void | any>;
|
|
42
|
+
get(): Promise<DocumentSnapshot<DocumentData>>;
|
|
43
|
+
update(data: DocumentData): Promise<void | any>;
|
|
44
|
+
delete(): Promise<void | any>;
|
|
45
|
+
stateChanges?: () => Observable<DocumentSnapshot<DocumentData>>;
|
|
46
|
+
}
|
|
47
|
+
export declare type FirestoreDocument<DocumentData> = DocumentReference<DocumentData>;
|
|
48
|
+
export interface FirestoreCollection<DocumentData, RawFirestoreCollection = any> {
|
|
49
|
+
__ref?: RawFirestoreCollection;
|
|
50
|
+
stateChanges?: () => Observable<DocumentChangeAction<DocumentData>[]>;
|
|
51
|
+
get(options?: GetOptions): Promise<QuerySnapshot<DocumentData>>;
|
|
52
|
+
}
|
|
53
|
+
export interface FirestoreCollectionGroup<DocumentData> {
|
|
54
|
+
__ref?: any;
|
|
55
|
+
stateChanges?: () => Observable<DocumentChangeAction<DocumentData>[]>;
|
|
56
|
+
get(options?: GetOptions): Promise<QuerySnapshot<DocumentData>>;
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/firestore/src/lib/interfaces/interfaces.ts"],"names":[],"mappings":";;AAmBC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx-ddd/firestore",
|
|
3
|
-
"version": "
|
|
4
|
-
"main": "
|
|
5
|
-
"
|
|
3
|
+
"version": "4.20.7",
|
|
4
|
+
"main": "./index.js",
|
|
5
|
+
"types": "./index.d.ts",
|
|
6
6
|
"dependencies": {},
|
|
7
7
|
"peerDependencies": {
|
|
8
|
-
"
|
|
9
|
-
"firebase
|
|
10
|
-
"
|
|
11
|
-
"@
|
|
12
|
-
"@
|
|
8
|
+
"firebase-admin": "^9.7.0",
|
|
9
|
+
"firebase": "^9.0.0",
|
|
10
|
+
"rxjs": "7.5.0",
|
|
11
|
+
"@angular/fire": "^7.5.0",
|
|
12
|
+
"@nx-ddd/core": "4.20.7",
|
|
13
|
+
"injection-js": "^2.4.0",
|
|
14
|
+
"reflect-metadata": "^0.1.13",
|
|
15
|
+
"lodash.pick": "^4.4.0",
|
|
16
|
+
"@nx-ddd/common": "4.20.7",
|
|
17
|
+
"lodash.camelcase": "^4.3.0",
|
|
18
|
+
"tslib": "^2.0.0"
|
|
13
19
|
}
|
|
14
20
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './path-builder';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/firestore/src/lib/path-builder/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare type CollectionParamMap<Entity extends {
|
|
2
|
+
id: string;
|
|
3
|
+
}> = Partial<Entity>;
|
|
4
|
+
declare type DocParamMap<Entity extends {
|
|
5
|
+
id: string;
|
|
6
|
+
}> = CollectionParamMap<Entity> & Pick<Entity, 'id'>;
|
|
7
|
+
export declare class FirestorePathBuilder<Entity extends {
|
|
8
|
+
id: string;
|
|
9
|
+
}> {
|
|
10
|
+
private paths;
|
|
11
|
+
doc: (param: DocParamMap<Entity>) => string;
|
|
12
|
+
collection: (param?: CollectionParamMap<Entity>) => string;
|
|
13
|
+
collectionGroup: () => string;
|
|
14
|
+
constructor(paths: string[]);
|
|
15
|
+
}
|
|
16
|
+
export declare const pathBuilderFactory: <E extends {
|
|
17
|
+
id: string;
|
|
18
|
+
}>(path: string) => FirestorePathBuilder<E>;
|
|
19
|
+
export declare const parsePath: (path: string) => string[];
|
|
20
|
+
export declare const resolvePaths: (obj: object, paths: string[]) => string;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvePaths = exports.parsePath = exports.pathBuilderFactory = exports.FirestorePathBuilder = void 0;
|
|
4
|
+
class FirestorePathBuilder {
|
|
5
|
+
constructor(paths) {
|
|
6
|
+
this.paths = paths;
|
|
7
|
+
this.doc = (param) => (0, exports.resolvePaths)(param, this.paths);
|
|
8
|
+
this.collection = (param = {}) => (0, exports.resolvePaths)(param, this.paths.slice(0, -1));
|
|
9
|
+
this.collectionGroup = () => this.paths[this.paths.length - 2];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.FirestorePathBuilder = FirestorePathBuilder;
|
|
13
|
+
const pathBuilderFactory = (path) => {
|
|
14
|
+
const paths = (0, exports.parsePath)(path);
|
|
15
|
+
return new FirestorePathBuilder(paths);
|
|
16
|
+
};
|
|
17
|
+
exports.pathBuilderFactory = pathBuilderFactory;
|
|
18
|
+
const parsePath = (path) => {
|
|
19
|
+
const paths = path.split('/').filter(p => p.length);
|
|
20
|
+
if (!paths[paths.length - 1].startsWith(':'))
|
|
21
|
+
paths.push(':id');
|
|
22
|
+
return paths;
|
|
23
|
+
};
|
|
24
|
+
exports.parsePath = parsePath;
|
|
25
|
+
const resolvePaths = (obj, paths) => {
|
|
26
|
+
return paths.map((path) => path.startsWith(':') ? resolvePath(obj, path.slice(1)) : path).join('/');
|
|
27
|
+
};
|
|
28
|
+
exports.resolvePaths = resolvePaths;
|
|
29
|
+
const resolvePath = (obj, key) => {
|
|
30
|
+
if (!(obj === null || obj === void 0 ? void 0 : obj[key]))
|
|
31
|
+
throw new Error(`Invalid key is detected in resolving paths, key: ${key}, obj: ${obj}`);
|
|
32
|
+
return obj === null || obj === void 0 ? void 0 : obj[key];
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=path-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-builder.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/firestore/src/lib/path-builder/path-builder.ts"],"names":[],"mappings":";;;AAGA,MAAa,oBAAoB;IAK/B,YAAoB,KAAe;QAAf,UAAK,GAAL,KAAK,CAAU;QAJnC,QAAG,GAAG,CAAC,KAA0B,EAAE,EAAE,CAAC,IAAA,oBAAY,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACtE,eAAU,GAAG,CAAC,QAAoC,EAAE,EAAE,EAAE,CAAC,IAAA,oBAAY,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACtG,oBAAe,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAC,CAAC,CAAC,CAAC;IAEjB,CAAC;CACzC;AAND,oDAMC;AAEM,MAAM,kBAAkB,GAAG,CAChC,IAAY,EACa,EAAE;IAC3B,MAAM,KAAK,GAAG,IAAA,iBAAS,EAAC,IAAI,CAAC,CAAC;IAC9B,OAAO,IAAI,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC,CAAC;AALW,QAAA,kBAAkB,sBAK7B;AAEK,MAAM,SAAS,GAAG,CAAC,IAAY,EAAY,EAAE;IAClD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACpD,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9D,OAAO,KAAK,CAAC;AACf,CAAC,CAAA;AAJY,QAAA,SAAS,aAIrB;AAEM,MAAM,YAAY,GAAG,CAAC,GAAW,EAAE,KAAe,EAAU,EAAE;IACnE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACtG,CAAC,CAAA;AAFY,QAAA,YAAY,gBAExB;AAED,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE;IAC/C,IAAI,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAG,GAAG,CAAC,CAAA;QAAE,MAAM,IAAI,KAAK,CAAC,oDAAoD,GAAG,UAAU,GAAG,EAAE,CAAC,CAAC;IACzG,OAAO,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAG,GAAG,CAAC,CAAC;AACpB,CAAC,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import { Observable, ReplaySubject } from 'rxjs';
|
|
3
|
+
import { FirestoreAdapter } from '../adapters/base';
|
|
4
|
+
import { FirestoreConverter } from '../converter';
|
|
5
|
+
import { FirestoreDAO } from '../dao';
|
|
6
|
+
import { FirestorePathBuilder } from '../path-builder';
|
|
7
|
+
import { FirestoreCollection, FirestoreCollectionGroup, ToFirestoreData } from '../interfaces';
|
|
8
|
+
declare type CollectionRef<D> = FirestoreCollection<D> | FirestoreCollectionGroup<D>;
|
|
9
|
+
export declare class FirestoreQuery<Entity extends {
|
|
10
|
+
id: string;
|
|
11
|
+
} = any, FirestoreData = ToFirestoreData<Entity, dayjs.Dayjs>> extends FirestoreDAO<Entity, FirestoreData> {
|
|
12
|
+
protected pathBuilder: FirestorePathBuilder<Entity>;
|
|
13
|
+
protected collection$: ReplaySubject<CollectionRef<FirestoreData>>;
|
|
14
|
+
switchCollection(paramMap?: Partial<Entity>): void;
|
|
15
|
+
protected get list$(): Observable<Entity[]>;
|
|
16
|
+
protected _list$: Observable<Entity[]>;
|
|
17
|
+
constructor(adapter: FirestoreAdapter, converter: FirestoreConverter<Entity>, pathBuilder: FirestorePathBuilder<Entity>);
|
|
18
|
+
listChanges(paramMap?: Partial<Entity>): Observable<Entity[]>;
|
|
19
|
+
changes({ id }: Partial<Entity>): Observable<Entity>;
|
|
20
|
+
get({ id }: Partial<Entity> & {
|
|
21
|
+
id: string;
|
|
22
|
+
}): Promise<Entity>;
|
|
23
|
+
list(paramMap?: Partial<Entity>): Promise<Entity[]>;
|
|
24
|
+
protected _listChanges(collection: FirestoreCollection<FirestoreData> | FirestoreCollectionGroup<FirestoreData>): Observable<Entity[]>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FirestoreQuery = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const dao_1 = require("../dao");
|
|
7
|
+
class FirestoreQuery extends dao_1.FirestoreDAO {
|
|
8
|
+
constructor(adapter, converter, pathBuilder) {
|
|
9
|
+
super(adapter, converter);
|
|
10
|
+
this.pathBuilder = pathBuilder;
|
|
11
|
+
this.collection$ = new rxjs_1.ReplaySubject(1);
|
|
12
|
+
this.switchCollection();
|
|
13
|
+
}
|
|
14
|
+
switchCollection(paramMap) {
|
|
15
|
+
const collectionRef = paramMap ? this.collection(paramMap) : this.collectionGroup();
|
|
16
|
+
this.collection$.next(collectionRef);
|
|
17
|
+
}
|
|
18
|
+
get list$() {
|
|
19
|
+
var _a;
|
|
20
|
+
return (_a = this._list$) !== null && _a !== void 0 ? _a : (this._list$ = this.collection$.pipe((0, operators_1.switchMap)((collection) => this._listChanges(collection)), (0, operators_1.shareReplay)(1)));
|
|
21
|
+
}
|
|
22
|
+
listChanges(paramMap) {
|
|
23
|
+
this.switchCollection(paramMap);
|
|
24
|
+
return this.list$;
|
|
25
|
+
}
|
|
26
|
+
changes({ id }) {
|
|
27
|
+
if (!id)
|
|
28
|
+
throw new Error(`Invalid Id. it must be Truthy`);
|
|
29
|
+
return this.list$.pipe((0, operators_1.map)(entities => entities.find(entity => entity.id === id)), (0, operators_1.distinctUntilChanged)((pre, cur) => JSON.stringify(pre) === JSON.stringify(cur)));
|
|
30
|
+
}
|
|
31
|
+
get({ id }) {
|
|
32
|
+
return this.list$.pipe((0, operators_1.take)(1), (0, operators_1.map)(entities => entities.find(entity => entity.id === id))).toPromise();
|
|
33
|
+
}
|
|
34
|
+
list(paramMap) {
|
|
35
|
+
return this.list$.pipe((0, operators_1.take)(1)).toPromise();
|
|
36
|
+
}
|
|
37
|
+
_listChanges(collection) {
|
|
38
|
+
const _map = new Map();
|
|
39
|
+
return collection.stateChanges().pipe((0, operators_1.tap)(actions => actions.forEach(({ type, payload: { doc } }) => {
|
|
40
|
+
if (new Set(['added', 'modified']).has(type)) {
|
|
41
|
+
_map.set(doc.id, this.converter.fromRecord(doc));
|
|
42
|
+
}
|
|
43
|
+
else if (type === 'removed') {
|
|
44
|
+
_map.delete(doc.id);
|
|
45
|
+
}
|
|
46
|
+
})), (0, operators_1.map)(() => [..._map.values()]));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.FirestoreQuery = FirestoreQuery;
|
|
50
|
+
//# sourceMappingURL=firestore.query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore.query.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/firestore/src/lib/query/firestore.query.ts"],"names":[],"mappings":";;;AACA,+BAAiD;AACjD,8CAA8F;AAG9F,gCAAsC;AAMtC,MAAa,cAGX,SAAQ,kBAAmC;IAiB3C,YACE,OAAyB,EACzB,SAAqC,EAC3B,WAAyC;QAEnD,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAFhB,gBAAW,GAAX,WAAW,CAA8B;QAlB3C,gBAAW,GAAG,IAAI,oBAAa,CAA+B,CAAC,CAAC,CAAC;QAqBzE,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IArBD,gBAAgB,CAAC,QAA0B;QACzC,MAAM,aAAa,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;QACpF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;IACtC,CAAC;IAED,IAAc,KAAK;;QACjB,aAAO,IAAI,CAAC,MAAM,oCAAX,IAAI,CAAC,MAAM,GAAK,IAAI,CAAC,WAAW,CAAC,IAAI,CAC1C,IAAA,qBAAS,EAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,EACxD,IAAA,uBAAW,EAAC,CAAC,CAAC,CACf,EAAC;IAEJ,CAAC;IAYD,WAAW,CAAC,QAA0B;QACpC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,OAAO,CAAC,EAAC,EAAE,EAAkB;QAC3B,IAAI,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK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AC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;aAClD;iBAAM,IAAI,IAAI,KAAK,SAAS,EAAE;gBAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;aACrB;QACH,CAAC,CAAC,CAAC,EACH,IAAA,eAAG,EAAC,GAAG,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAC9B,CAAC;IACJ,CAAC;CACF;AArED,wCAqEC"}
|
package/query/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './firestore.query';
|
package/query/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/firestore/src/lib/query/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Entity } from '@nx-ddd/common/domain/models';
|
|
2
|
+
import { FirestoreQuery } from '../query';
|
|
3
|
+
export interface Firestore<EntityClass extends typeof Entity = any> {
|
|
4
|
+
Entity: EntityClass;
|
|
5
|
+
path?: string;
|
|
6
|
+
Query?: typeof FirestoreQuery;
|
|
7
|
+
}
|
|
8
|
+
export declare function FirestoreRepository({ Entity, Query, path, }: Firestore): <T extends new (...args: any[]) => {}>(target: T) => any;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FirestoreRepository = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@nx-ddd/core");
|
|
6
|
+
const lodash_camelcase_1 = tslib_1.__importDefault(require("lodash.camelcase"));
|
|
7
|
+
const base_1 = require("../adapters/base");
|
|
8
|
+
const converter_1 = require("../converter");
|
|
9
|
+
const path_builder_1 = require("../path-builder");
|
|
10
|
+
const query_1 = require("../query");
|
|
11
|
+
const repository_1 = require("../repository");
|
|
12
|
+
function FirestoreRepository({ Entity,
|
|
13
|
+
// Converter,
|
|
14
|
+
Query, path, }) {
|
|
15
|
+
return function (target) {
|
|
16
|
+
// const __ConverterClass = Converter ?? FirestoreConverter;
|
|
17
|
+
const __QueryClass = Query !== null && Query !== void 0 ? Query : query_1.FirestoreQuery;
|
|
18
|
+
const __path = path !== null && path !== void 0 ? path : resolvePathByEntity(Entity);
|
|
19
|
+
let _ = class _ extends repository_1.BaseFirestoreRepository {
|
|
20
|
+
constructor(adapter) {
|
|
21
|
+
super(adapter);
|
|
22
|
+
this.pathBuilder = (0, path_builder_1.pathBuilderFactory)(__path);
|
|
23
|
+
this.collectionPath = __path;
|
|
24
|
+
this.converter = (0, converter_1.createConverter)(Entity, this.adapter);
|
|
25
|
+
this.query = new __QueryClass(this.adapter, this.converter, this.pathBuilder);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
_ = tslib_1.__decorate([
|
|
29
|
+
(0, core_1.Injectable)(),
|
|
30
|
+
tslib_1.__metadata("design:paramtypes", [base_1.FirestoreAdapter])
|
|
31
|
+
], _);
|
|
32
|
+
;
|
|
33
|
+
Object.defineProperty(_, 'name', { value: target.name, writable: false });
|
|
34
|
+
return _;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.FirestoreRepository = FirestoreRepository;
|
|
38
|
+
function resolvePathByEntity(EntityClass) {
|
|
39
|
+
return `${(0, lodash_camelcase_1.default)(EntityClass.name)}s`;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/firestore/src/lib/repository/decorator.ts"],"names":[],"mappings":";;;;AAAA,uCAA0C;AAE1C,gFAAyC;AACzC,2CAAoD;AACpD,4CAAmE;AACnE,kDAAqD;AACrD,oCAA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+1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./
|
|
4
|
+
tslib_1.__exportStar(require("./decorator"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./repository"), exports);
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/firestore/src/lib/repository/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,uDAA6B"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { PartialWithId, Repository } from '@nx-ddd/common/domain/repository';
|
|
2
|
+
import { FirestoreAdapter } from '../adapters/base';
|
|
3
|
+
import { FirestoreConverter } from '../converter';
|
|
4
|
+
import { FirestorePathBuilder } from '../path-builder';
|
|
5
|
+
import { FirestoreCollection, FirestoreCollectionGroup, FirestoreDocument, ToFirestoreData } from '../interfaces';
|
|
6
|
+
import { Dayjs } from 'dayjs';
|
|
7
|
+
export declare abstract class BaseFirestoreRepository<Entity extends {
|
|
8
|
+
id: string;
|
|
9
|
+
}, FirestoreData = ToFirestoreData<Entity, Dayjs>> extends Repository<Entity> {
|
|
10
|
+
protected adapter: FirestoreAdapter;
|
|
11
|
+
protected Entity: {
|
|
12
|
+
new (): Entity;
|
|
13
|
+
};
|
|
14
|
+
protected abstract collectionPath: string;
|
|
15
|
+
protected abstract converter: FirestoreConverter;
|
|
16
|
+
protected pathBuilder: FirestorePathBuilder<Entity>;
|
|
17
|
+
constructor(adapter: FirestoreAdapter);
|
|
18
|
+
list(paramMap?: Partial<Entity>, query?: any): Promise<any[]>;
|
|
19
|
+
get(paramMap?: Partial<Entity>): Promise<any>;
|
|
20
|
+
save(entity: Entity): Promise<[Entity, boolean]>;
|
|
21
|
+
create(entity: Partial<Entity>): Promise<Entity>;
|
|
22
|
+
update(entity: PartialWithId<Entity>): Promise<void>;
|
|
23
|
+
delete(paramMap: Partial<Entity>): Promise<void>;
|
|
24
|
+
bulkWrite(entities: Entity[], timestamps?: string[]): Promise<void>;
|
|
25
|
+
bulkCreate(entities: Entity[]): Promise<void>;
|
|
26
|
+
bulkUpdate(entities: PartialWithId<Entity>[]): Promise<void>;
|
|
27
|
+
protected collection(paramMap?: Partial<Entity>): FirestoreCollection<FirestoreData>;
|
|
28
|
+
protected collectionGroup(): FirestoreCollectionGroup<FirestoreData>;
|
|
29
|
+
protected doc(paramMap: PartialWithId<Entity>): FirestoreDocument<FirestoreData>;
|
|
30
|
+
protected genId: () => string;
|
|
31
|
+
protected _list(collection: FirestoreCollection<FirestoreData>): Promise<any[]>;
|
|
32
|
+
protected _get(doc: FirestoreDocument<FirestoreData>): Promise<any>;
|
|
33
|
+
protected _save(doc: FirestoreDocument<FirestoreData>, entity: Entity): Promise<[Entity, boolean]>;
|
|
34
|
+
protected _create(doc: FirestoreDocument<FirestoreData>, entity: Entity): Promise<Entity>;
|
|
35
|
+
protected _update(doc: FirestoreDocument<FirestoreData>, entity: Partial<Entity>): Promise<void>;
|
|
36
|
+
protected _set(doc: FirestoreDocument<FirestoreData>, entity: Partial<Entity>, isUpdate?: boolean): Promise<import("../interfaces").DocumentSnapshot<FirestoreData>>;
|
|
37
|
+
protected buildServerTimestampObject(keys?: string[]): {};
|
|
38
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseFirestoreRepository = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@nx-ddd/core");
|
|
6
|
+
const repository_1 = require("@nx-ddd/common/domain/repository");
|
|
7
|
+
const base_1 = require("../adapters/base");
|
|
8
|
+
const to_object_1 = require("@nx-ddd/common/utilities/to-object");
|
|
9
|
+
const utilities_1 = require("@nx-ddd/common/utilities");
|
|
10
|
+
const toPromise = callback => new Promise((resolve, reject) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
try {
|
|
12
|
+
resolve(callback());
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
reject(error);
|
|
16
|
+
}
|
|
17
|
+
}));
|
|
18
|
+
let BaseFirestoreRepository = class BaseFirestoreRepository extends repository_1.Repository {
|
|
19
|
+
constructor(adapter) {
|
|
20
|
+
super();
|
|
21
|
+
this.adapter = adapter;
|
|
22
|
+
this.genId = () => (0, utilities_1.generateId)();
|
|
23
|
+
}
|
|
24
|
+
list(paramMap, query = q => q) {
|
|
25
|
+
const collection = paramMap ? this.collection(paramMap) : this.collectionGroup();
|
|
26
|
+
return this._list(query(collection));
|
|
27
|
+
}
|
|
28
|
+
get(paramMap) {
|
|
29
|
+
return this._get(this.doc(paramMap));
|
|
30
|
+
}
|
|
31
|
+
save(entity) {
|
|
32
|
+
// TODO(nontangent): なんでここの型定義でasがいるのか考える。
|
|
33
|
+
return this._save(this.doc({ id: (entity === null || entity === void 0 ? void 0 : entity.id) || this.genId() }), entity);
|
|
34
|
+
}
|
|
35
|
+
create(entity) {
|
|
36
|
+
const obj = (0, to_object_1.toObject)(entity);
|
|
37
|
+
const id = (obj === null || obj === void 0 ? void 0 : obj.id) || this.genId();
|
|
38
|
+
return toPromise(() => this.doc(Object.assign(Object.assign({}, obj), { id }))).then(doc => this._create(doc, entity));
|
|
39
|
+
}
|
|
40
|
+
update(entity) {
|
|
41
|
+
return toPromise(() => this.doc(entity)).then(doc => this._update(doc, entity));
|
|
42
|
+
}
|
|
43
|
+
delete(paramMap) {
|
|
44
|
+
return this.doc(paramMap).delete();
|
|
45
|
+
}
|
|
46
|
+
bulkWrite(entities, timestamps = []) {
|
|
47
|
+
return entities.reduce((batch, entity) => {
|
|
48
|
+
const doc = this.doc(entity).__ref;
|
|
49
|
+
return batch.set(doc, Object.assign(Object.assign({}, this.converter.toRecord(entity)), this.buildServerTimestampObject(timestamps)));
|
|
50
|
+
}, this.adapter.batch()).commit();
|
|
51
|
+
}
|
|
52
|
+
bulkCreate(entities) {
|
|
53
|
+
// TODO(nontangent): add maximum 500 record validation
|
|
54
|
+
return entities.reduce((batch, entity) => {
|
|
55
|
+
const doc = this.doc(entity).__ref;
|
|
56
|
+
return batch.create(doc, Object.assign(Object.assign({}, this.converter.toRecord(entity)), this.buildServerTimestampObject(['createdAt', 'updatedAt'])));
|
|
57
|
+
}, this.adapter.batch()).commit();
|
|
58
|
+
}
|
|
59
|
+
bulkUpdate(entities) {
|
|
60
|
+
// TODO(nontangent): add maximum 500 record validation
|
|
61
|
+
return entities.reduce((batch, entity) => {
|
|
62
|
+
const doc = this.doc(entity).__ref;
|
|
63
|
+
return batch.update(doc, Object.assign(Object.assign({}, this.converter.toRecord(entity)), this.buildServerTimestampObject(['updatedAt'])));
|
|
64
|
+
}, this.adapter.batch()).commit();
|
|
65
|
+
}
|
|
66
|
+
collection(paramMap) {
|
|
67
|
+
const path = this.pathBuilder.collection(paramMap);
|
|
68
|
+
return this.adapter.collection(path);
|
|
69
|
+
}
|
|
70
|
+
collectionGroup() {
|
|
71
|
+
const path = this.pathBuilder.collectionGroup();
|
|
72
|
+
return this.adapter.collectionGroup(path);
|
|
73
|
+
}
|
|
74
|
+
doc(paramMap) {
|
|
75
|
+
const path = this.pathBuilder.doc(paramMap);
|
|
76
|
+
return this.adapter.doc(path);
|
|
77
|
+
}
|
|
78
|
+
_list(collection) {
|
|
79
|
+
return collection.get().then(({ docs }) => docs.map(doc => this.converter.fromRecord(doc)));
|
|
80
|
+
}
|
|
81
|
+
_get(doc) {
|
|
82
|
+
return doc.get().then((doc => this.converter.fromRecord(doc)));
|
|
83
|
+
}
|
|
84
|
+
_save(doc, entity) {
|
|
85
|
+
return this._set(doc, entity, !(entity === null || entity === void 0 ? void 0 : entity.id))
|
|
86
|
+
.then(doc => this.converter.fromRecord(doc)).then(e => [e, !!(entity === null || entity === void 0 ? void 0 : entity.id)]);
|
|
87
|
+
}
|
|
88
|
+
_create(doc, entity) {
|
|
89
|
+
return doc.set(Object.assign(Object.assign({}, this.converter.toRecord(entity)), this.buildServerTimestampObject(['createdAt', 'updatedAt']))).then(() => doc.get()).then(doc => this.converter.fromRecord(doc));
|
|
90
|
+
;
|
|
91
|
+
}
|
|
92
|
+
_update(doc, entity) {
|
|
93
|
+
return doc.update(Object.assign(Object.assign({}, this.converter.toRecord(entity)), this.buildServerTimestampObject(['updatedAt']))).then(() => { });
|
|
94
|
+
}
|
|
95
|
+
_set(doc, entity, isUpdate = true) {
|
|
96
|
+
return doc.set(Object.assign(Object.assign({}, this.converter.toRecord(entity)), this.buildServerTimestampObject(isUpdate ? ['updatedAt'] : [])), { merge: isUpdate }).then(() => doc.get());
|
|
97
|
+
}
|
|
98
|
+
buildServerTimestampObject(keys = ['createdAt', 'updatedAt']) {
|
|
99
|
+
return keys.reduce((m, k) => (Object.assign(Object.assign({}, m), { [k]: this.adapter.FieldValue.serverTimestamp() })), {});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
BaseFirestoreRepository = tslib_1.__decorate([
|
|
103
|
+
(0, core_1.Injectable)(),
|
|
104
|
+
tslib_1.__metadata("design:paramtypes", [base_1.FirestoreAdapter])
|
|
105
|
+
], BaseFirestoreRepository);
|
|
106
|
+
exports.BaseFirestoreRepository = BaseFirestoreRepository;
|
|
107
|
+
//# sourceMappingURL=repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/firestore/src/lib/repository/repository.ts"],"names":[],"mappings":";;;;AAAA,uCAA0C;AAC1C,iEAA6E;AAC7E,2CAAoD;AAGpD,kEAA8D;AAG9D,wDAAsD;AAEtD,MAAM,SAAS,GAAG,QAAQ,CAAC,EAAE,CAAC,IAAI,OAAO,CAA8B,CAAO,OAAO,EAAE,MAAM,EAAE,EAAE;IAC/F,IAAI;QAAE,OAA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AAE,MAAuB;QAC9E,OAAO,GAAG,CAAC,MAAM,CAAC,gCACb,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,GAC/B,IAAI,CAAC,0BAA0B,CAAC,CAAC,WAAW,CAAC,CAAC,CAC3C,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC3B,CAAC;IAES,IAAI,CAAC,GAAqC,EAAE,MAAuB,EAAE,QAAQ,GAAG,IAAI;QAC5F,OAAO,GAAG,CAAC,GAAG,CAAC,gCACV,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,GAC/B,IAAI,CAAC,0BAA0B,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAC3D,EAAE,EAAC,KAAK,EAAE,QAAQ,EAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;IACrD,CAAC;IAES,0BAA0B,CAAC,OAAiB,CAAC,WAAW,EAAE,WAAW,CAAC;QAC9E,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,iCAAK,CAAC,KAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,eAAe,EAAE,IAAE,EAAE,EAAE,CAAC,CAAC;IAC7F,CAAC;CAEF,CAAA;AAhIqB,uBAAuB;IAD5C,IAAA,iBAAU,GAAE;6CAWU,uBAAgB;GAVjB,uBAAuB,CAgI5C;AAhIqB,0DAAuB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import { AdminFirestoreAdapter } from '../adapters/admin';
|
|
3
|
+
export declare const testAdapterFactory: () => AdminFirestoreAdapter;
|
|
4
|
+
export declare const timestampFactory: (dt: dayjs.Dayjs) => FirebaseFirestore.Timestamp;
|
|
5
|
+
export declare function initializeTest(projectId?: string): AdminFirestoreAdapter;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initializeTest = exports.timestampFactory = exports.testAdapterFactory = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const firebase_admin_1 = tslib_1.__importDefault(require("firebase-admin"));
|
|
6
|
+
const admin_1 = require("../adapters/admin");
|
|
7
|
+
const testAdapterFactory = () => new admin_1.AdminFirestoreAdapter(firebase_admin_1.default.firestore());
|
|
8
|
+
exports.testAdapterFactory = testAdapterFactory;
|
|
9
|
+
const timestampFactory = (dt) => {
|
|
10
|
+
return firebase_admin_1.default.firestore.Timestamp.fromDate(dt.toDate());
|
|
11
|
+
};
|
|
12
|
+
exports.timestampFactory = timestampFactory;
|
|
13
|
+
function initializeTest(projectId = 'nx-ddd') {
|
|
14
|
+
process.env['FIRESTORE_EMULATOR_HOST'] = 'localhost:8080';
|
|
15
|
+
firebase_admin_1.default.initializeApp({ projectId });
|
|
16
|
+
return (0, exports.testAdapterFactory)();
|
|
17
|
+
}
|
|
18
|
+
exports.initializeTest = initializeTest;
|
|
19
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/firestore/src/lib/testing/common.ts"],"names":[],"mappings":";;;;AAAA,4EAAmC;AAEnC,6CAA0D;AAEnD,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAAC,IAAI,6BAAqB,CAAC,wBAAK,CAAC,SAAS,EAAE,CAAC,CAAC;AAAxE,QAAA,kBAAkB,sBAAsD;AAE9E,MAAM,gBAAgB,GAAG,CAAC,EAAe,EAAE,EAAE;IAClD,OAAO,wBAAK,CAAC,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;AACzD,CAAC,CAAC;AAFW,QAAA,gBAAgB,oBAE3B;AAEF,SAAgB,cAAc,CAAC,YAAoB,QAAQ;IACzD,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,GAAG,gBAAgB,CAAC;IAC1D,wBAAK,CAAC,aAAa,CAAC,EAAC,SAAS,EAAC,CAAC,CAAC;IACjC,OAAO,IAAA,0BAAkB,GAAE,CAAC;AAC9B,CAAC;AAJD,wCAIC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Entity } from '@nx-ddd/common/domain/models';
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
export declare class Transaction extends Entity {
|
|
4
|
+
dealAt: dayjs.Dayjs;
|
|
5
|
+
static readonly FIELDS: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare class UserTransaction extends Transaction {
|
|
8
|
+
userId: string;
|
|
9
|
+
static readonly FIELDS: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare const testTransaction: Entity<string>;
|
|
12
|
+
export declare const testUserTransaction: Entity<string>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testUserTransaction = exports.testTransaction = exports.UserTransaction = exports.Transaction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const models_1 = require("@nx-ddd/common/domain/models");
|
|
6
|
+
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
7
|
+
class Transaction extends models_1.Entity {
|
|
8
|
+
}
|
|
9
|
+
exports.Transaction = Transaction;
|
|
10
|
+
Transaction.FIELDS = ['dealAt', 'createdAt', 'updatedAt'];
|
|
11
|
+
class UserTransaction extends Transaction {
|
|
12
|
+
}
|
|
13
|
+
exports.UserTransaction = UserTransaction;
|
|
14
|
+
UserTransaction.FIELDS = ['dealAt', 'createdAt', 'updatedAt'];
|
|
15
|
+
exports.testTransaction = Transaction.fromObj({
|
|
16
|
+
id: 'test-transaction-0001',
|
|
17
|
+
dealAt: (0, dayjs_1.default)('2018-02-01'),
|
|
18
|
+
createdAt: (0, dayjs_1.default)('2022-01-01'),
|
|
19
|
+
updatedAt: (0, dayjs_1.default)('2022-01-01'),
|
|
20
|
+
});
|
|
21
|
+
exports.testUserTransaction = Transaction.fromObj(Object.assign(Object.assign({}, exports.testTransaction), { userId: 'test-user-0001' }));
|
|
22
|
+
//# sourceMappingURL=domain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/firestore/src/lib/testing/domain.ts"],"names":[],"mappings":";;;;AAAA,yDAAsD;AACtD,0DAA0B;AAE1B,MAAa,WAAY,SAAQ,eAAM;;AAAvC,kCAIC;AADiB,kBAAM,GAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AAGhE,MAAa,eAAgB,SAAQ,WAAW;;AAAhD,0CAIC;AADiB,sBAAM,GAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AAGnD,QAAA,eAAe,GAAG,WAAW,CAAC,OAAO,CAAC;IACjD,EAAE,EAAE,uBAAuB;IAC3B,MAAM,EAAE,IAAA,eAAK,EAAC,YAAY,CAAC;IAC3B,SAAS,EAAE,IAAA,eAAK,EAAC,YAAY,CAAC;IAC9B,SAAS,EAAE,IAAA,eAAK,EAAC,YAAY,CAAC;CAC/B,CAAC,CAAC;AAEU,QAAA,mBAAmB,GAAG,WAAW,CAAC,OAAO,iCACjD,uBAAe,KAClB,MAAM,EAAE,gBAAgB,IACxB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./
|
|
5
|
-
tslib_1.__exportStar(require("./
|
|
4
|
+
tslib_1.__exportStar(require("./common"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./domain"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./repository"), exports);
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/@nx-ddd/firestore/src/lib/testing/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,mDAAyB;AACzB,uDAA6B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Repository } from "@nx-ddd/common/domain/repository";
|
|
2
|
+
import { Transaction, UserTransaction } from "./domain";
|
|
3
|
+
export declare class TransactionRepository extends Repository<Transaction> {
|
|
4
|
+
}
|
|
5
|
+
export declare class UserTransactionRepository extends Repository<UserTransaction> {
|
|
6
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserTransactionRepository = exports.TransactionRepository = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const repository_1 = require("@nx-ddd/common/domain/repository");
|
|
6
|
+
const repository_2 = require("../repository");
|
|
7
|
+
const domain_1 = require("./domain");
|
|
8
|
+
let TransactionRepository = class TransactionRepository extends repository_1.Repository {
|
|
9
|
+
};
|
|
10
|
+
TransactionRepository = tslib_1.__decorate([
|
|
11
|
+
(0, repository_2.FirestoreRepository)({
|
|
12
|
+
Entity: domain_1.Transaction,
|
|
13
|
+
path: 'transactions',
|
|
14
|
+
})
|
|
15
|
+
], TransactionRepository);
|
|
16
|
+
exports.TransactionRepository = TransactionRepository;
|
|
17
|
+
let UserTransactionRepository = class UserTransactionRepository extends repository_1.Repository {
|
|
18
|
+
};
|
|
19
|
+
UserTransactionRepository = tslib_1.__decorate([
|
|
20
|
+
(0, repository_2.FirestoreRepository)({
|
|
21
|
+
Entity: domain_1.UserTransaction,
|
|
22
|
+
path: `users/:userId/transactions`,
|
|
23
|
+
})
|
|
24
|
+
], UserTransactionRepository);
|
|
25
|
+
exports.UserTransactionRepository = UserTransactionRepository;
|
|
26
|
+
//# sourceMappingURL=repository.js.map
|