@dereekb/firebase 8.7.6 → 8.9.0
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/CHANGELOG.md +23 -0
- package/package.json +5 -5
- package/src/lib/common/firestore/snapshot/index.d.ts +1 -0
- package/src/lib/common/firestore/snapshot/index.js +1 -0
- package/src/lib/common/firestore/snapshot/index.js.map +1 -1
- package/src/lib/common/firestore/snapshot/snapshot.d.ts +1 -64
- package/src/lib/common/firestore/snapshot/snapshot.field.d.ts +62 -4
- package/src/lib/common/firestore/snapshot/snapshot.field.js +70 -5
- package/src/lib/common/firestore/snapshot/snapshot.field.js.map +1 -1
- package/src/lib/common/firestore/snapshot/snapshot.js +7 -10
- package/src/lib/common/firestore/snapshot/snapshot.js.map +1 -1
- package/src/lib/common/firestore/snapshot/snapshot.type.d.ts +61 -0
- package/src/lib/common/firestore/snapshot/snapshot.type.js +8 -0
- package/src/lib/common/firestore/snapshot/snapshot.type.js.map +1 -0
- package/src/lib/common/model/model.service.js.map +1 -1
- package/test/CHANGELOG.md +12 -0
- package/test/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
# [8.9.0](https://github.com/dereekb/dbx-components/compare/v8.8.1-dev...v8.9.0) (2022-06-30)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* added firestoreLatLngString() ([2af3e5f](https://github.com/dereekb/dbx-components/commit/2af3e5fcbcae665994df5cc68d1c246b5417a07d))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [8.8.1](https://github.com/dereekb/dbx-components/compare/v8.8.0-dev...v8.8.1) (2022-06-29)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# [8.8.0](https://github.com/dereekb/dbx-components/compare/v8.7.6-dev...v8.8.0) (2022-06-29)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* added FirestoreObjectArray ([e1050eb](https://github.com/dereekb/dbx-components/commit/e1050eb53c816025e016a07e2d7e41ee8c24362a))
|
|
24
|
+
* added firestoreSubObjectField() ([3d6fbe1](https://github.com/dereekb/dbx-components/commit/3d6fbe17a10dfddf3e9bc1cecd522ed61efd6c49))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
5
28
|
## [8.7.6](https://github.com/dereekb/dbx-components/compare/v8.7.5-dev...v8.7.6) (2022-06-29)
|
|
6
29
|
|
|
7
30
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/firebase",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.9.0",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@firebase/rules-unit-testing": "^2.0.0"
|
|
6
6
|
},
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
"rxfire": "^6.0.3",
|
|
24
24
|
"rxjs": "^7.0.0",
|
|
25
25
|
"firebase": "^9.8.0",
|
|
26
|
-
"@dereekb/util": "8.
|
|
26
|
+
"@dereekb/util": "8.9.0",
|
|
27
27
|
"make-error": "^1.3.0",
|
|
28
28
|
"ts-essentials": "^9.1.2",
|
|
29
29
|
"extra-set": "^2.2.11",
|
|
30
|
-
"@dereekb/rxjs": "8.
|
|
30
|
+
"@dereekb/rxjs": "8.9.0",
|
|
31
31
|
"ms": "^3.0.0-canary.1",
|
|
32
|
-
"@dereekb/model": "8.
|
|
32
|
+
"@dereekb/model": "8.9.0",
|
|
33
33
|
"class-transformer": "^0.5.1",
|
|
34
34
|
"class-validator": "^0.13.2",
|
|
35
|
-
"@dereekb/date": "8.
|
|
35
|
+
"@dereekb/date": "8.9.0",
|
|
36
36
|
"date-fns": "^2.28.0",
|
|
37
37
|
"date-fns-tz": "^1.3.0",
|
|
38
38
|
"rrule": "2.7.0",
|
|
@@ -3,4 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./snapshot"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./snapshot.field"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./snapshot.type"), exports);
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/firebase/src/lib/common/firestore/snapshot/index.ts"],"names":[],"mappings":";;;AAAA,qDAA2B;AAC3B,2DAAiC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/firebase/src/lib/common/firestore/snapshot/index.ts"],"names":[],"mappings":";;;AAAA,qDAA2B;AAC3B,2DAAiC;AACjC,0DAAgC"}
|
|
@@ -1,65 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SnapshotOptions, SetOptions, DocumentSnapshot, FirestoreDataConverter } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* The default "empty" value in the Firestore.
|
|
5
|
-
*/
|
|
6
|
-
export declare const FIRESTORE_EMPTY_VALUE: null;
|
|
7
|
-
/**
|
|
8
|
-
* The expected firestore document data for a specific type.
|
|
9
|
-
*
|
|
10
|
-
* This declaration allows a second type to defined overrides for how the data is stored within Firestore. For example, since by default
|
|
11
|
-
* this library choses to store dates as an ISO8601String, you can strictly specify that, and gain the type checking benefits.
|
|
12
|
-
*/
|
|
13
|
-
export declare type ExpectedFirestoreModelData<T extends object, R extends object = object> = TypedMappedModelData<T, R>;
|
|
14
|
-
/**
|
|
15
|
-
* What is considered the typings for the true "stored" data.
|
|
16
|
-
*
|
|
17
|
-
* All items are marked as partial and Maybe. This is because by design the firestore has no schema and has no obligation to require fields.
|
|
18
|
-
* It is better to be cognizant of this fact in our typings, and let the Snapshot conversions handle this.
|
|
19
|
-
*
|
|
20
|
-
* Fields that existing on the database type can only replace typings on the specific type, and not declare new typings.
|
|
21
|
-
* This is to prevent accidents related to adding/removing fields but not adding the correct conversions.
|
|
22
|
-
*
|
|
23
|
-
* This declaration allows a second type to defined overrides for how the data is stored within Firestore. For example, since by default
|
|
24
|
-
* this library choses to store dates as an ISO8601String, you can strictly specify that, and gain the type checking benefits. For other data types
|
|
25
|
-
* that are the same in the datastore as they are here, they are considered "any".
|
|
26
|
-
*
|
|
27
|
-
* The reason for this is that FirestoreModelData types are typically never used directly, execept for our snapshotConverterFunctions(),
|
|
28
|
-
* and using the built-in snapshot firestore field converters. Unless we have specified a strict new type that we expect in the data,
|
|
29
|
-
* most of the time we are unconcerned with the final type of our ExpectedFirestoreModelData.
|
|
30
|
-
*
|
|
31
|
-
* This is a more lose type that takes the above into account. You will only see typing information for fields of R that override the converted type T.
|
|
32
|
-
* If you find yourself needing full typings, extend ExpectedFirestoreModelData instead.
|
|
33
|
-
*
|
|
34
|
-
* Example:
|
|
35
|
-
*
|
|
36
|
-
* export interface MockItem {
|
|
37
|
-
* string: string;
|
|
38
|
-
* date: Date;
|
|
39
|
-
* }
|
|
40
|
-
*
|
|
41
|
-
* export type MockItemData = ExpectedFirestoreModelData<MockItem, {
|
|
42
|
-
* // string field is not defined directly, will be treated as any.
|
|
43
|
-
* date: string; // we want typescript typing help for this in our converters.
|
|
44
|
-
* }>;
|
|
45
|
-
*
|
|
46
|
-
*/
|
|
47
|
-
export declare type FirestoreModelData<T extends object, R extends object = object> = Partial<ExpectedFirestoreModelData<T, MaybeMap<R>>>;
|
|
48
|
-
export declare type SnapshotConverterConfigWithFields<T extends object, O extends object = FirestoreModelData<T>> = {
|
|
49
|
-
readonly fields: ModelFieldConversionsConfig<T, O>;
|
|
50
|
-
};
|
|
51
|
-
export declare type SnapshotConverterConfigWithConversions<T extends object, O extends object = FirestoreModelData<T>> = {
|
|
52
|
-
readonly fieldConversions: ModelFieldConversions<T, O>;
|
|
53
|
-
};
|
|
54
|
-
export declare type SnapshotConverterModifier<T extends object, O extends object = FirestoreModelData<T>> = PartialModelModifier<T, O>;
|
|
55
|
-
export declare type SnapshotConverterConfig<T extends object, O extends object = FirestoreModelData<T>> = (SnapshotConverterConfigWithFields<T, O> | SnapshotConverterConfigWithConversions<T, O>) & {
|
|
56
|
-
readonly modifiers?: ArrayOrValue<SnapshotConverterModifier<T, O>>;
|
|
57
|
-
};
|
|
58
|
-
export interface SnapshotConverterFunctions<T extends object, O extends object = FirestoreModelData<T>> extends FirestoreDataConverter<T, O> {
|
|
59
|
-
from: SnapshotConverterFromFunction<T, O>;
|
|
60
|
-
to: SnapshotConverterToFunction<T, O>;
|
|
61
|
-
}
|
|
62
|
-
export declare type SnapshotConverterFromFirestoreFunction<T extends object, O extends object = FirestoreModelData<T>> = (snapshot: DocumentSnapshot<O>, options?: SnapshotOptions) => T;
|
|
63
|
-
export declare type SnapshotConverterFromFunction<T extends object, O extends object = FirestoreModelData<T>> = ApplyMapFunctionWithOptions<DocumentSnapshot<O>, T, SnapshotOptions>;
|
|
64
|
-
export declare type SnapshotConverterToFunction<T extends object, O extends object = FirestoreModelData<T>> = ApplyMapFunctionWithOptions<T, O, SetOptions>;
|
|
1
|
+
import { FirestoreModelData, SnapshotConverterConfig, SnapshotConverterFunctions } from './snapshot.type';
|
|
65
2
|
export declare function snapshotConverterFunctions<T extends object, O extends object = FirestoreModelData<T>>(config: SnapshotConverterConfig<T, O>): SnapshotConverterFunctions<T, O>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GrantedRole } from '@dereekb/model';
|
|
2
|
-
import { ModelFieldMapFunctionsConfig, GetterOrValue, Maybe, ModelFieldMapConvertFunction, PrimativeKey, ReadKeyFunction, ModelFieldMapFunctionsWithDefaultsConfig, FindUniqueFunction, FindUniqueStringsTransformConfig, MapFunction, FilterKeyValueTuplesInput, ModelKey } from '@dereekb/util';
|
|
2
|
+
import { ModelFieldMapFunctionsConfig, GetterOrValue, Maybe, ModelFieldMapConvertFunction, PrimativeKey, ReadKeyFunction, ModelFieldMapFunctionsWithDefaultsConfig, FindUniqueFunction, FindUniqueStringsTransformConfig, MapFunction, FilterKeyValueTuplesInput, ModelKey, ToModelMapFunctionsInput, ModelMapFunctinosRef, TransformStringFunctionConfig, LatLngPrecision, TransformStringFunction, LatLngString } from '@dereekb/util';
|
|
3
|
+
import { FirestoreModelData } from './snapshot.type';
|
|
3
4
|
export interface BaseFirestoreFieldConfig<V, D = unknown> {
|
|
4
5
|
fromData: ModelFieldMapConvertFunction<D, V>;
|
|
5
6
|
toData: ModelFieldMapConvertFunction<V, D>;
|
|
@@ -29,11 +30,15 @@ export declare type MapConfiguredFirestoreFieldConfigWithDefaultData<V, D = unkn
|
|
|
29
30
|
export declare type MapConfiguredFirestoreFieldConfig<V, D = unknown> = MapConfiguredFirestoreFieldConfigWithDefault<V, D> | MapConfiguredFirestoreFieldConfigWithDefaultData<V, D>;
|
|
30
31
|
export declare type DefaultMapConfiguredFirestoreFieldConfig<V, D = unknown> = Omit<FirestoreFieldConfigWithDefault<V, D>, 'fromData' | 'toData' | 'default'> & Partial<Pick<FirestoreFieldConfigWithDefault<V, D>, 'default'>>;
|
|
31
32
|
export declare type OptionalMapConfiguredFirestoreFieldConfig<V, D = unknown> = Omit<BaseFirestoreFieldConfig<V, D>, 'fromData' | 'toData' | 'defaultBeforeSave'>;
|
|
32
|
-
export
|
|
33
|
+
export declare type FirestoreStringTransformOptions<S extends string = string> = TransformStringFunctionConfig | TransformStringFunction<S>;
|
|
34
|
+
export interface FirestoreStringConfig<S extends string = string> extends DefaultMapConfiguredFirestoreFieldConfig<S, S> {
|
|
35
|
+
transform?: FirestoreStringTransformOptions;
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated: use transform field instead.
|
|
38
|
+
*/
|
|
33
39
|
trim?: boolean;
|
|
34
40
|
}
|
|
35
|
-
export
|
|
36
|
-
}
|
|
41
|
+
export declare const DEFAULT_FIRESTORE_STRING_FIELD_VALUE = "";
|
|
37
42
|
export declare function firestoreString<S extends string = string>(config?: FirestoreStringConfig<S>): FirestoreModelFieldMapFunctionsConfig<S, S>;
|
|
38
43
|
export declare function optionalFirestoreString(): ModelFieldMapFunctionsConfig<Maybe<string>, Maybe<string>>;
|
|
39
44
|
export declare type FirestoreEnumConfig<S extends string | number> = MapConfiguredFirestoreFieldConfigWithDefault<S, S>;
|
|
@@ -150,6 +155,59 @@ export declare function firestoreModelKeyGrantedRoleArrayMap<R extends GrantedRo
|
|
|
150
155
|
* Filters empty roles/arrays by default.
|
|
151
156
|
*/
|
|
152
157
|
export declare const firestoreModelIdGrantedRoleArrayMap: () => FirestoreModelFieldMapFunctionsConfig<FirestoreMapFieldType<ModelKey[], string>, FirestoreMapFieldType<ModelKey[], string>>;
|
|
158
|
+
/**
|
|
159
|
+
* firestoreObjectArray configuration
|
|
160
|
+
*/
|
|
161
|
+
export declare type FirestoreObjectArrayFieldConfig<T extends object, O extends object = FirestoreModelData<T>> = DefaultMapConfiguredFirestoreFieldConfig<T[], O[]> & {
|
|
162
|
+
/**
|
|
163
|
+
* The field to use for conversion.
|
|
164
|
+
*/
|
|
165
|
+
readonly objectField: ToModelMapFunctionsInput<T, O>;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* A Firestore array that maps each array value using another FirestoreFieldConfig config.
|
|
169
|
+
*
|
|
170
|
+
* @param config
|
|
171
|
+
* @returns
|
|
172
|
+
*/
|
|
173
|
+
export declare function firestoreObjectArray<T extends object, O extends object = FirestoreModelData<T>>(config: FirestoreObjectArrayFieldConfig<T, O>): FirestoreModelFieldMapFunctionsConfig<T[], O[]>;
|
|
174
|
+
/**
|
|
175
|
+
* firestoreSubObjectField configuration
|
|
176
|
+
*/
|
|
177
|
+
export declare type FirestoreSubObjectFieldConfig<T extends object, O extends object = FirestoreModelData<T>> = DefaultMapConfiguredFirestoreFieldConfig<T, O> & {
|
|
178
|
+
/**
|
|
179
|
+
* Whether or not to save the default object. Is ignored if defaultBeforeSave is set.
|
|
180
|
+
*
|
|
181
|
+
* Is false by default.
|
|
182
|
+
*/
|
|
183
|
+
saveDefaultObject?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* The fields to use for conversion.
|
|
186
|
+
*/
|
|
187
|
+
objectField: ToModelMapFunctionsInput<T, O>;
|
|
188
|
+
};
|
|
189
|
+
export declare type FirestoreSubObjectFieldMapFunctionsConfig<T extends object, O extends object = FirestoreModelData<T>> = FirestoreModelFieldMapFunctionsConfig<T, O> & ModelMapFunctinosRef<T, O>;
|
|
190
|
+
/**
|
|
191
|
+
* A nested object field that uses other FirestoreFieldConfig configurations to map a field.
|
|
192
|
+
*/
|
|
193
|
+
export declare function firestoreSubObject<T extends object, O extends object = FirestoreModelData<T>>(config: FirestoreSubObjectFieldConfig<T, O>): FirestoreSubObjectFieldMapFunctionsConfig<T, O>;
|
|
194
|
+
export interface FirestoreLatLngStringConfig extends DefaultMapConfiguredFirestoreFieldConfig<LatLngString, LatLngString> {
|
|
195
|
+
precision?: LatLngPrecision;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Default value used by firestoreLatLngString
|
|
199
|
+
*/
|
|
200
|
+
export declare const DEFAULT_FIRESTORE_LAT_LNG_STRING_VALUE = "0,0";
|
|
201
|
+
/**
|
|
202
|
+
* Configuration for a LatLngString field.
|
|
203
|
+
*
|
|
204
|
+
* NOTE: The preference is to store LatLng values as strings as opposed to a lat/lng object or value pair as we could not sort/search lat and lng together, so indexing on them is useless.
|
|
205
|
+
* By storing them as a string we can add lat/lng to an object (implements the LatLngStringRef interface) using a single field, and can easily utilize the data object(s) using latLngDataPointFunction() to map the input.
|
|
206
|
+
*
|
|
207
|
+
* @param config
|
|
208
|
+
* @returns
|
|
209
|
+
*/
|
|
210
|
+
export declare function firestoreLatLngString(config?: FirestoreLatLngStringConfig): FirestoreModelFieldMapFunctionsConfig<`${number},${number}`, `${number},${number}`>;
|
|
153
211
|
export declare type FirestoreSetFieldConfig<T extends string | number> = DefaultMapConfiguredFirestoreFieldConfig<Set<T>, T[]>;
|
|
154
212
|
/**
|
|
155
213
|
* Do not use.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.firestoreSet = exports.firestoreModelIdGrantedRoleArrayMap = exports.firestoreModelKeyGrantedRoleArrayMap = exports.firestoreArrayMap = exports.firestoreModelIdGrantedRoleMap = exports.firestoreModelKeyGrantedRoleMap = exports.firestoreMap = exports.firestoreEncodedArray = exports.firestoreModelIdArrayField = exports.firestoreModelKeyArrayField = exports.firestoreUniqueStringArray = exports.firestoreEnumArray = exports.firestoreUniqueKeyedArray = exports.firestoreUniqueArray = exports.optionalFirestoreArray = exports.firestoreArray = exports.optionalFirestoreNumber = exports.firestoreNumber = exports.optionalFirestoreBoolean = exports.firestoreBoolean = exports.optionalFirestoreDate = exports.firestoreDate = exports.firestoreModelIdString = exports.firestoreModelKeyString = exports.optionalFirestoreUID = exports.firestoreUID = exports.optionalFirestoreEnum = exports.firestoreEnum = exports.optionalFirestoreString = exports.firestoreString = exports.firestorePassThroughField = exports.FIRESTORE_PASSTHROUGH_FIELD = exports.firestoreField = void 0;
|
|
3
|
+
exports.firestoreSet = exports.firestoreLatLngString = exports.DEFAULT_FIRESTORE_LAT_LNG_STRING_VALUE = exports.firestoreSubObject = exports.firestoreObjectArray = exports.firestoreModelIdGrantedRoleArrayMap = exports.firestoreModelKeyGrantedRoleArrayMap = exports.firestoreArrayMap = exports.firestoreModelIdGrantedRoleMap = exports.firestoreModelKeyGrantedRoleMap = exports.firestoreMap = exports.firestoreEncodedArray = exports.firestoreModelIdArrayField = exports.firestoreModelKeyArrayField = exports.firestoreUniqueStringArray = exports.firestoreEnumArray = exports.firestoreUniqueKeyedArray = exports.firestoreUniqueArray = exports.optionalFirestoreArray = exports.firestoreArray = exports.optionalFirestoreNumber = exports.firestoreNumber = exports.optionalFirestoreBoolean = exports.firestoreBoolean = exports.optionalFirestoreDate = exports.firestoreDate = exports.firestoreModelIdString = exports.firestoreModelKeyString = exports.optionalFirestoreUID = exports.firestoreUID = exports.optionalFirestoreEnum = exports.firestoreEnum = exports.optionalFirestoreString = exports.firestoreString = exports.DEFAULT_FIRESTORE_STRING_FIELD_VALUE = exports.firestorePassThroughField = exports.FIRESTORE_PASSTHROUGH_FIELD = exports.firestoreField = void 0;
|
|
4
4
|
const date_1 = require("@dereekb/date");
|
|
5
5
|
const util_1 = require("@dereekb/util");
|
|
6
|
-
const
|
|
6
|
+
const snapshot_type_1 = require("./snapshot.type");
|
|
7
7
|
function firestoreField(config) {
|
|
8
8
|
var _a;
|
|
9
9
|
return {
|
|
@@ -17,7 +17,7 @@ function firestoreField(config) {
|
|
|
17
17
|
convert: config.fromData
|
|
18
18
|
},
|
|
19
19
|
to: {
|
|
20
|
-
default: ((_a = config.defaultBeforeSave) !== null && _a !== void 0 ? _a :
|
|
20
|
+
default: ((_a = config.defaultBeforeSave) !== null && _a !== void 0 ? _a : snapshot_type_1.FIRESTORE_EMPTY_VALUE),
|
|
21
21
|
convert: config.toData
|
|
22
22
|
}
|
|
23
23
|
};
|
|
@@ -32,9 +32,11 @@ function firestorePassThroughField() {
|
|
|
32
32
|
return exports.FIRESTORE_PASSTHROUGH_FIELD;
|
|
33
33
|
}
|
|
34
34
|
exports.firestorePassThroughField = firestorePassThroughField;
|
|
35
|
+
exports.DEFAULT_FIRESTORE_STRING_FIELD_VALUE = '';
|
|
35
36
|
function firestoreString(config) {
|
|
36
|
-
const
|
|
37
|
-
|
|
37
|
+
const transform = (config === null || config === void 0 ? void 0 : config.transform) ? (typeof config.transform === 'function' ? { transform: config === null || config === void 0 ? void 0 : config.transform } : config === null || config === void 0 ? void 0 : config.transform) : (config === null || config === void 0 ? void 0 : config.trim) ? { trim: true } : undefined;
|
|
38
|
+
const transformData = transform ? (0, util_1.transformStringFunction)(transform) : util_1.passThrough;
|
|
39
|
+
return firestoreField(Object.assign(Object.assign({ default: exports.DEFAULT_FIRESTORE_STRING_FIELD_VALUE }, config), { fromData: transformData, toData: transformData }));
|
|
38
40
|
}
|
|
39
41
|
exports.firestoreString = firestoreString;
|
|
40
42
|
function optionalFirestoreString() {
|
|
@@ -232,6 +234,69 @@ exports.firestoreModelKeyGrantedRoleArrayMap = firestoreModelKeyGrantedRoleArray
|
|
|
232
234
|
* Filters empty roles/arrays by default.
|
|
233
235
|
*/
|
|
234
236
|
exports.firestoreModelIdGrantedRoleArrayMap = firestoreModelKeyGrantedRoleArrayMap;
|
|
237
|
+
/**
|
|
238
|
+
* A Firestore array that maps each array value using another FirestoreFieldConfig config.
|
|
239
|
+
*
|
|
240
|
+
* @param config
|
|
241
|
+
* @returns
|
|
242
|
+
*/
|
|
243
|
+
function firestoreObjectArray(config) {
|
|
244
|
+
var _a;
|
|
245
|
+
const { from, to } = (0, util_1.toModelMapFunctions)(config.objectField);
|
|
246
|
+
return firestoreField({
|
|
247
|
+
default: (_a = config.default) !== null && _a !== void 0 ? _a : (() => []),
|
|
248
|
+
defaultBeforeSave: config.defaultBeforeSave,
|
|
249
|
+
fromData: (input) => input.map((x) => from(x)),
|
|
250
|
+
toData: (input) => (0, util_1.filterMaybeValues)(input).map((x) => to(x))
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
exports.firestoreObjectArray = firestoreObjectArray;
|
|
254
|
+
/**
|
|
255
|
+
* A nested object field that uses other FirestoreFieldConfig configurations to map a field.
|
|
256
|
+
*/
|
|
257
|
+
function firestoreSubObject(config) {
|
|
258
|
+
var _a, _b;
|
|
259
|
+
const mapFunctions = (0, util_1.toModelMapFunctions)(config.objectField);
|
|
260
|
+
const { from: fromData, to: toData } = mapFunctions;
|
|
261
|
+
const defaultWithFields = () => fromData({});
|
|
262
|
+
const defaultBeforeSave = (_a = config.defaultBeforeSave) !== null && _a !== void 0 ? _a : (config.saveDefaultObject ? () => toData({}) : null);
|
|
263
|
+
const mapFunctionsConfig = (0, util_1.build)({
|
|
264
|
+
base: firestoreField({
|
|
265
|
+
default: (_b = config.default) !== null && _b !== void 0 ? _b : defaultWithFields,
|
|
266
|
+
defaultBeforeSave,
|
|
267
|
+
fromData,
|
|
268
|
+
toData
|
|
269
|
+
}),
|
|
270
|
+
build: (x) => {
|
|
271
|
+
x.mapFunctions = mapFunctions;
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
return mapFunctionsConfig;
|
|
275
|
+
}
|
|
276
|
+
exports.firestoreSubObject = firestoreSubObject;
|
|
277
|
+
/**
|
|
278
|
+
* Default value used by firestoreLatLngString
|
|
279
|
+
*/
|
|
280
|
+
exports.DEFAULT_FIRESTORE_LAT_LNG_STRING_VALUE = '0,0';
|
|
281
|
+
/**
|
|
282
|
+
* Configuration for a LatLngString field.
|
|
283
|
+
*
|
|
284
|
+
* NOTE: The preference is to store LatLng values as strings as opposed to a lat/lng object or value pair as we could not sort/search lat and lng together, so indexing on them is useless.
|
|
285
|
+
* By storing them as a string we can add lat/lng to an object (implements the LatLngStringRef interface) using a single field, and can easily utilize the data object(s) using latLngDataPointFunction() to map the input.
|
|
286
|
+
*
|
|
287
|
+
* @param config
|
|
288
|
+
* @returns
|
|
289
|
+
*/
|
|
290
|
+
function firestoreLatLngString(config) {
|
|
291
|
+
const { default: defaultValue, defaultBeforeSave, precision } = config !== null && config !== void 0 ? config : {};
|
|
292
|
+
const transform = (0, util_1.latLngStringFunction)({ precision, validate: true });
|
|
293
|
+
return firestoreString({
|
|
294
|
+
default: defaultValue || exports.DEFAULT_FIRESTORE_LAT_LNG_STRING_VALUE,
|
|
295
|
+
defaultBeforeSave,
|
|
296
|
+
transform
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
exports.firestoreLatLngString = firestoreLatLngString;
|
|
235
300
|
/**
|
|
236
301
|
* Do not use.
|
|
237
302
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.field.js","sourceRoot":"","sources":["../../../../../../../../packages/firebase/src/lib/common/firestore/snapshot/snapshot.field.ts"],"names":[],"mappings":";;;AAEA,wCAA4E;AAC5E,
|
|
1
|
+
{"version":3,"file":"snapshot.field.js","sourceRoot":"","sources":["../../../../../../../../packages/firebase/src/lib/common/firestore/snapshot/snapshot.field.ts"],"names":[],"mappings":";;;AAEA,wCAA4E;AAC5E,wCAoCuB;AACvB,mDAA4E;AA6B5E,SAAgB,cAAc,CAAiB,MAAkC;;IAC/E,OAAO;QACL,IAAI,EACD,MAAgD,CAAC,OAAO,IAAI,IAAI;YAC/D,CAAC,CAAC;gBACE,OAAO,EAAG,MAAgD,CAAC,OAAO;gBAClE,OAAO,EAAE,MAAM,CAAC,QAAQ;aACzB;YACH,CAAC,CAAC;gBACE,YAAY,EAAG,MAAoD,CAAC,WAAW;gBAC/E,OAAO,EAAE,MAAM,CAAC,QAAQ;aACzB;QACP,EAAE,EAAE;YACF,OAAO,EAAE,CAAC,MAAA,MAAM,CAAC,iBAAiB,mCAAI,qCAAqB,CAAqB;YAChF,OAAO,EAAE,MAAM,CAAC,MAAM;SACvB;KAC6C,CAAC;AACnD,CAAC;AAjBD,wCAiBC;AAEY,QAAA,2BAA2B,GAAG,cAAc,CAAmB;IAC1E,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,kBAAW;IACrB,MAAM,EAAE,kBAAW;CACpB,CAAC,CAAC;AAEH,SAAgB,yBAAyB;IACvC,OAAO,mCAAiE,CAAC;AAC3E,CAAC;AAFD,8DAEC;AAmBY,QAAA,oCAAoC,GAAG,EAAE,CAAC;AAEvD,SAAgB,eAAe,CAA4B,MAAiC;IAC1F,MAAM,SAAS,GAAyC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,EAAC,CAAC,CAAC,CAAC,OAAO,MAAM,CAAC,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,EAA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S,GAAG,IAAA,2BAAoB,EAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAEtE,OAAO,eAAe,CAAe;QACnC,OAAO,EAAE,YAAY,IAAI,8CAAsC;QAC/D,iBAAiB;QACjB,SAAS;KACV,CAAC,CAAC;AACL,CAAC;AATD,sDASC;AAKD;;;;;;;GAOG;AACH,SAAgB,YAAY,CAA4B,MAAkC;;IACxF,OAAO,cAAc,CAAc;QACjC,OAAO,EAAE,MAAA,MAAM,CAAC,OAAO,mCAAI,CAAC,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC;QAC5C,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC;QACjC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;KACjC,CAAC,CAAC;AACL,CAAC;AAND,oCAMC"}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.snapshotConverterFunctions =
|
|
3
|
+
exports.snapshotConverterFunctions = void 0;
|
|
4
4
|
const util_1 = require("@dereekb/util");
|
|
5
5
|
const types_1 = require("../types");
|
|
6
|
-
// MARK:
|
|
7
|
-
/**
|
|
8
|
-
* The default "empty" value in the Firestore.
|
|
9
|
-
*/
|
|
10
|
-
exports.FIRESTORE_EMPTY_VALUE = null;
|
|
6
|
+
// MARK: Snapshots
|
|
11
7
|
function snapshotConverterFunctions(config) {
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const mapFunctions = (0, util_1.
|
|
15
|
-
const { from: fromData, to: toData } =
|
|
8
|
+
const conversions = (0, util_1.toModelFieldConversions)(config);
|
|
9
|
+
const baseMapFunctions = (0, util_1.makeModelMapFunctions)(conversions);
|
|
10
|
+
const mapFunctions = config.modifiers ? (0, util_1.modifyModelMapFunctions)({ mapFunctions: baseMapFunctions, modifiers: config.modifiers }) : baseMapFunctions;
|
|
11
|
+
const { from: fromData, to: toData } = mapFunctions;
|
|
16
12
|
const from = (input, target) => {
|
|
17
13
|
const data = input.data();
|
|
18
14
|
return fromData(data, target);
|
|
@@ -35,6 +31,7 @@ function snapshotConverterFunctions(config) {
|
|
|
35
31
|
return {
|
|
36
32
|
from,
|
|
37
33
|
to,
|
|
34
|
+
mapFunctions,
|
|
38
35
|
fromFirestore: (snapshot, options) => from(snapshot, undefined, options),
|
|
39
36
|
toFirestore: (modelObject, options) => to(modelObject, undefined, options)
|
|
40
37
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../../../../../../../packages/firebase/src/lib/common/firestore/snapshot/snapshot.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../../../../../../../packages/firebase/src/lib/common/firestore/snapshot/snapshot.ts"],"names":[],"mappings":";;;AAAA,wCAA8J;AAC9J,oCAA8K;AAG9K,kBAAkB;AAClB,SAAgB,0BAA0B,CAA6D,MAAqC;IAC1I,MAAM,WAAW,GAAgC,IAAA,8BAAuB,EAAO,MAAM,CAAC,CAAC;IACvF,MAAM,gBAAgB,GAAG,IAAA,4BAAqB,EAAO,WAAW,CAAC,CAAC;IAClE,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,8BAAuB,EAAC,EAAE,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC;IACpJ,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC;IAEpD,MAAM,IAAI,GAAwC,CAAC,KAAuB,EAAE,MAA0B,EAAE,EAAE;QACxG,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAC,IAAS,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC,CAAC;IAEF,MAAM,EAAE,GAAsC,CAAC,KAAQ,EAAE,MAA0B,EAAE,OAA2B,EAAE,EAAE;QAClH,IAAI,SAA2C,CAAC;QAEhD,IAAI,OAAO,EAAE;YACX,MAAM,WAAW,GAAI,OAAiC,CAAC,WAAW,CAAC;YAEnE,IAAK,OAA2B,CAAC,KAAK,EAAE;gBACtC,SAAS,GAAG;oBACV,WAAW,EAAE,IAAI;iBAClB,CAAC;aACH;YAED,IAAI,WAAW,EAAE;gBACf,SAAS,mCACJ,SAAS,KACZ,MAAM,EAAE,IAAA,4BAAoB,EAAC,WAAW,CAAgB,GACzD,CAAC;aACH;SACF;QAED,OAAO,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAC1C,CAAC,CAAC;IAEF,OAAO;QACL,IAAI;QACJ,EAAE;QACF,YAAY;QACZ,aAAa,EAAE,CAAC,QAA6B,EAAE,OAAyB,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;QAC/G,WAAW,EAAE,CAAC,WAAyD,EAAE,OAAoB,EAAE,EAAE,CAAC,EAAE,CAAC,WAAgB,EAAE,SAAS,EAAE,OAAO,CAAC;KAC3I,CAAC;AACJ,CAAC;AAzCD,gEAyCC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ApplyMapFunctionWithOptions, ArrayOrValue, MaybeMap, ModelFieldConversionsConfigRef, ModelFieldConversionsRef, ModelMapFunctions, PartialModelModifier, TypedMappedModelData } from '@dereekb/util';
|
|
2
|
+
import { FirestoreDataConverter, DocumentSnapshot, SetOptions, SnapshotOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* The default "empty" value in the Firestore.
|
|
5
|
+
*/
|
|
6
|
+
export declare const FIRESTORE_EMPTY_VALUE: null;
|
|
7
|
+
/**
|
|
8
|
+
* The expected firestore document data for a specific type.
|
|
9
|
+
*
|
|
10
|
+
* This declaration allows a second type to defined overrides for how the data is stored within Firestore. For example, since by default
|
|
11
|
+
* this library choses to store dates as an ISO8601String, you can strictly specify that, and gain the type checking benefits.
|
|
12
|
+
*/
|
|
13
|
+
export declare type ExpectedFirestoreModelData<T extends object, R extends object = object> = TypedMappedModelData<T, R>;
|
|
14
|
+
/**
|
|
15
|
+
* What is considered the typings for the true "stored" data.
|
|
16
|
+
*
|
|
17
|
+
* All items are marked as partial and Maybe. This is because by design the firestore has no schema and has no obligation to require fields.
|
|
18
|
+
* It is better to be cognizant of this fact in our typings, and let the Snapshot conversions handle this.
|
|
19
|
+
*
|
|
20
|
+
* Fields that existing on the database type can only replace typings on the specific type, and not declare new typings.
|
|
21
|
+
* This is to prevent accidents related to adding/removing fields but not adding the correct conversions.
|
|
22
|
+
*
|
|
23
|
+
* This declaration allows a second type to defined overrides for how the data is stored within Firestore. For example, since by default
|
|
24
|
+
* this library choses to store dates as an ISO8601String, you can strictly specify that, and gain the type checking benefits. For other data types
|
|
25
|
+
* that are the same in the datastore as they are here, they are considered "any".
|
|
26
|
+
*
|
|
27
|
+
* The reason for this is that FirestoreModelData types are typically never used directly, execept for our snapshotConverterFunctions(),
|
|
28
|
+
* and using the built-in snapshot firestore field converters. Unless we have specified a strict new type that we expect in the data,
|
|
29
|
+
* most of the time we are unconcerned with the final type of our ExpectedFirestoreModelData.
|
|
30
|
+
*
|
|
31
|
+
* This is a more lose type that takes the above into account. You will only see typing information for fields of R that override the converted type T.
|
|
32
|
+
* If you find yourself needing full typings, extend ExpectedFirestoreModelData instead.
|
|
33
|
+
*
|
|
34
|
+
* Example:
|
|
35
|
+
*
|
|
36
|
+
* export interface MockItem {
|
|
37
|
+
* string: string;
|
|
38
|
+
* date: Date;
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* export type MockItemData = ExpectedFirestoreModelData<MockItem, {
|
|
42
|
+
* // string field is not defined directly, will be treated as any.
|
|
43
|
+
* date: string; // we want typescript typing help for this in our converters.
|
|
44
|
+
* }>;
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
export declare type FirestoreModelData<T extends object, R extends object = object> = Partial<ExpectedFirestoreModelData<T, MaybeMap<R>>>;
|
|
48
|
+
export declare type SnapshotConverterConfigWithFields<T extends object, O extends object = FirestoreModelData<T>> = ModelFieldConversionsConfigRef<T, O>;
|
|
49
|
+
export declare type SnapshotConverterConfigWithConversions<T extends object, O extends object = FirestoreModelData<T>> = ModelFieldConversionsRef<T, O>;
|
|
50
|
+
export declare type SnapshotConverterModifier<T extends object, O extends object = FirestoreModelData<T>> = PartialModelModifier<T, O>;
|
|
51
|
+
export declare type SnapshotConverterConfig<T extends object, O extends object = FirestoreModelData<T>> = (SnapshotConverterConfigWithFields<T, O> | SnapshotConverterConfigWithConversions<T, O>) & {
|
|
52
|
+
readonly modifiers?: ArrayOrValue<SnapshotConverterModifier<T, O>>;
|
|
53
|
+
};
|
|
54
|
+
export interface SnapshotConverterFunctions<T extends object, O extends object = FirestoreModelData<T>> extends FirestoreDataConverter<T, O> {
|
|
55
|
+
readonly from: SnapshotConverterFromFunction<T, O>;
|
|
56
|
+
readonly to: SnapshotConverterToFunction<T, O>;
|
|
57
|
+
readonly mapFunctions: ModelMapFunctions<T, O>;
|
|
58
|
+
}
|
|
59
|
+
export declare type SnapshotConverterFromFirestoreFunction<T extends object, O extends object = FirestoreModelData<T>> = (snapshot: DocumentSnapshot<O>, options?: SnapshotOptions) => T;
|
|
60
|
+
export declare type SnapshotConverterFromFunction<T extends object, O extends object = FirestoreModelData<T>> = ApplyMapFunctionWithOptions<DocumentSnapshot<O>, T, SnapshotOptions>;
|
|
61
|
+
export declare type SnapshotConverterToFunction<T extends object, O extends object = FirestoreModelData<T>> = ApplyMapFunctionWithOptions<T, O, SetOptions>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.type.js","sourceRoot":"","sources":["../../../../../../../../packages/firebase/src/lib/common/firestore/snapshot/snapshot.type.ts"],"names":[],"mappings":";;;AAGA;;GAEG;AACU,QAAA,qBAAqB,GAAG,IAAI,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.service.js","sourceRoot":"","sources":["../../../../../../../packages/firebase/src/lib/common/model/model.service.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,oGAAoG;;;AAGpG,
|
|
1
|
+
{"version":3,"file":"model.service.js","sourceRoot":"","sources":["../../../../../../../packages/firebase/src/lib/common/model/model.service.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,oGAAoG;;;AAGpG,wCAAqI;AAErI,mEAAuK;AACvK,uDAA6I;AAC7I,6CAA2R;AAC3R,kFAAsH;AAStH,SAAgB,oBAAoB,CAAuI,MAA8C;IACvN,MAAM,yBAAyB,GAAG,IAAA,YAAK,EAAwD;QAC7F,IAAI,EAAE,IAAA,kCAAmB,EAAC,MAAM,CAAC,sBAAsB,CAAC;QACxD,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE;YACX,CAAC,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;QAC7C,CAAC;KACF,CAAC,CAAC;IAEH,MAAM,iBAAiB,GAAG,IAAA,2CAA8B,EAAC,yBAAyB,CAAC,CAAC;IAEpF,MAAM,OAAO,GAAqC;QAChD,sBAAsB,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,iBAAiB,CAAC,sBAAsB,CAAC,KAAK,EAAE,OAAO,CAAC;QACpG,oBAAoB,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,GAAG,EAAE,OAAO,CAAC;QAC5F,eAAe,EAAE,yBAAyB,CAAC,eAAe;KAC3D,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC;AAjBD,oDAiBC;AAID,SAAgB,2BAA2B,CAAuI,MAA8C;IAC9N,OAAO,I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O,6BAA6B,CAAC;AACvC,CAAC;AAdD,sDAcC;AAKD;;;;;GAKG;AACH,SAAgB,qCAAqC,CAAiJ,OAAoC;IACxO,MAAM,qCAAqC,GAAuE,CAAoB,OAAU,EAAE,EAAE;QAClJ,OAAO,CAAC,IAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC,CAAC;IAEF,OAAO,qCAAqC,CAAC;AAC/C,CAAC;AAND,sFAMC;AAsBD,SAAgB,+BAA+B,CAAqF,OAAU,EAAE,IAAO,EAAE,MAA4C;IACnM,MAAM,GAAG,GAAG,IAAA,kCAAqB,EAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACpD,OAAO,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,GAAG,CAA+C,CAAC;AACjG,CAAC;AAHD,0EAGC;AAED,SAAgB,wBAAwB,CAAqF,OAAU,EAAE,IAAO,EAAE,MAA+C;IAC/L,MAAM,qBAAqB,GAAG,+BAA+B,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACrF,IAAI,MAAqD,CAAC;IAE1D,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE;QACvC,MAAM,GAAG,qBAAqB,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,gBAAgB,CAAkD,CAAC;KACnI;SAAM;QACL,MAAM,GAAG,qBAAqB,CAAC,GAAoD,CAAC;KACrF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAXD,4DAWC"}
|
package/test/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
# [8.9.0](https://github.com/dereekb/dbx-components/compare/v8.8.1-dev...v8.9.0) (2022-06-30)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## [8.8.1](https://github.com/dereekb/dbx-components/compare/v8.8.0-dev...v8.8.1) (2022-06-29)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# [8.8.0](https://github.com/dereekb/dbx-components/compare/v8.7.6-dev...v8.8.0) (2022-06-29)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
5
17
|
## [8.7.6](https://github.com/dereekb/dbx-components/compare/v8.7.5-dev...v8.7.6) (2022-06-29)
|
|
6
18
|
|
|
7
19
|
|
package/test/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/firebase/test",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.9.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"typings": "./src/index.d.ts",
|
|
7
7
|
"dependencies": {},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@dereekb/util/test": "8.
|
|
10
|
-
"@dereekb/util": "8.
|
|
9
|
+
"@dereekb/util/test": "8.9.0",
|
|
10
|
+
"@dereekb/util": "8.9.0",
|
|
11
11
|
"make-error": "^1.3.0",
|
|
12
12
|
"ts-essentials": "^9.1.2",
|
|
13
13
|
"extra-set": "^2.2.11",
|
|
14
|
-
"@dereekb/firebase": "8.
|
|
14
|
+
"@dereekb/firebase": "8.9.0",
|
|
15
15
|
"rxfire": "^6.0.3",
|
|
16
16
|
"rxjs": "^7.0.0",
|
|
17
17
|
"firebase": "^9.8.0",
|
|
18
|
-
"@dereekb/rxjs": "8.
|
|
18
|
+
"@dereekb/rxjs": "8.9.0",
|
|
19
19
|
"ms": "^3.0.0-canary.1",
|
|
20
|
-
"@dereekb/model": "8.
|
|
20
|
+
"@dereekb/model": "8.9.0",
|
|
21
21
|
"class-transformer": "^0.5.1",
|
|
22
22
|
"class-validator": "^0.13.2",
|
|
23
|
-
"@dereekb/date": "8.
|
|
23
|
+
"@dereekb/date": "8.9.0",
|
|
24
24
|
"date-fns": "^2.28.0",
|
|
25
25
|
"date-fns-tz": "^1.3.0",
|
|
26
26
|
"rrule": "2.7.0",
|