@mxpicture/gcp-functions-common 1.1.76 → 1.1.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helper/helper.annotation.d.ts +0 -2
- package/dist/helper/helper.annotation.d.ts.map +1 -1
- package/dist/helper/helper.annotation.js +1 -20
- package/dist/helper/helper.annotation.js.map +1 -1
- package/dist/helper/helper.date.d.ts +19 -23
- package/dist/helper/helper.date.d.ts.map +1 -1
- package/dist/helper/helper.date.js +64 -68
- package/dist/helper/helper.date.js.map +1 -1
- package/dist/helper/helper.timestamp.d.ts +26 -0
- package/dist/helper/helper.timestamp.d.ts.map +1 -0
- package/dist/helper/helper.timestamp.js +74 -0
- package/dist/helper/helper.timestamp.js.map +1 -0
- package/dist/helper/index.d.ts +1 -0
- package/dist/helper/index.d.ts.map +1 -1
- package/dist/helper/index.js +1 -0
- package/dist/helper/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -12,6 +12,4 @@ import { DocumentData } from "../types/types.document.js";
|
|
|
12
12
|
* @returns A partial document containing only the properties that define a default value.
|
|
13
13
|
*/
|
|
14
14
|
export declare const annoDocInitial: <T extends DocumentData>(properties: AnnotationsProperty<DecoPropertyBase>[]) => Partial<T>;
|
|
15
|
-
export declare const removeDate: (d: Date) => Date;
|
|
16
|
-
export declare const removeTime: (d: Date) => Date;
|
|
17
15
|
//# sourceMappingURL=helper.annotation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.annotation.d.ts","sourceRoot":"","sources":["../../src/helper/helper.annotation.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"helper.annotation.d.ts","sourceRoot":"","sources":["../../src/helper/helper.annotation.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG1D;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,YAAY,EACnD,YAAY,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,KAClD,OAAO,CAAC,CAAC,CAiDX,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { castDecoBoolean, castDecoDate, castDecoEnum, castDecoNumber, castDecoString, } from "../decorator/deco.cast.js";
|
|
2
2
|
import { DecoDateType } from "../decorator/deco.enum.js";
|
|
3
|
+
import { date1970, now, today } from "./helper.date.js";
|
|
3
4
|
/**
|
|
4
5
|
* Builds a partial document pre-filled with default values from annotation properties.
|
|
5
6
|
*
|
|
@@ -52,24 +53,4 @@ export const annoDocInitial = (properties) => {
|
|
|
52
53
|
}
|
|
53
54
|
return result;
|
|
54
55
|
};
|
|
55
|
-
const date1970 = (offsetDays = 0) => addDays(removeTime(removeDate(new Date())), offsetDays);
|
|
56
|
-
const today = (offsetDays = 0) => addDays(removeDate(new Date()), offsetDays);
|
|
57
|
-
const now = (offsetDays = 0) => addDays(new Date(), offsetDays);
|
|
58
|
-
const addDays = (date, offsetDays) => {
|
|
59
|
-
date.setDate(date.getDate() + (offsetDays ?? 0));
|
|
60
|
-
return date;
|
|
61
|
-
};
|
|
62
|
-
export const removeDate = (d) => {
|
|
63
|
-
d.setUTCFullYear(1970);
|
|
64
|
-
d.setUTCMonth(0);
|
|
65
|
-
d.setUTCDate(1);
|
|
66
|
-
return d;
|
|
67
|
-
};
|
|
68
|
-
export const removeTime = (d) => {
|
|
69
|
-
d.setUTCHours(0);
|
|
70
|
-
d.setUTCMinutes(0);
|
|
71
|
-
d.setUTCSeconds(0);
|
|
72
|
-
d.setUTCMilliseconds(0);
|
|
73
|
-
return d;
|
|
74
|
-
};
|
|
75
56
|
//# sourceMappingURL=helper.annotation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.annotation.js","sourceRoot":"","sources":["../../src/helper/helper.annotation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,cAAc,GACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"helper.annotation.js","sourceRoot":"","sources":["../../src/helper/helper.annotation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,cAAc,GACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAIzD,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAExD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,UAAmD,EACvC,EAAE;IACd,MAAM,MAAM,GAAe,EAAE,CAAC;IAE9B,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,WAAsB,CAAC;QAExC,MAAM,aAAa,GACjB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;YACvB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;YACzB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;YACzB,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAI,aAAa,EAAE,CAAC;YAClB,8DAA8D;YAC9D,IAAI,aAAa,CAAC,OAAO;gBAAG,MAAc,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC;YACxE,SAAS;QACX,CAAC;QAED,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,GAAG,GAAgB,IAAI,CAAC;YAE5B,QAAQ,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBAC1B,KAAK,YAAY,CAAC,QAAQ;oBACxB,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;oBACxC,MAAM;gBAER,KAAK,YAAY,CAAC,GAAG;oBACnB,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;oBACnC,MAAM;gBAER,KAAK,YAAY,CAAC,KAAK;oBACrB,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;oBACrC,MAAM;gBAER;oBACE,MAAM;YACV,CAAC;YAED,8DAA8D;YAC9D,IAAI,GAAG;gBAAG,MAAc,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;YACpC,SAAS;QACX,CAAC;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjC,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS;YACnC,8DAA8D;YAC7D,MAAc,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IAC/B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -1,26 +1,22 @@
|
|
|
1
|
+
export declare enum ModifyDateUnit {
|
|
2
|
+
seconds = "seconds",
|
|
3
|
+
minutes = "minutes",
|
|
4
|
+
hours = "hours",
|
|
5
|
+
days = "days"
|
|
6
|
+
}
|
|
7
|
+
export declare const date1970: (offset?: number | null | undefined, unit?: ModifyDateUnit) => Date;
|
|
8
|
+
export declare const today: (offset?: number | null | undefined, unit?: ModifyDateUnit) => Date;
|
|
9
|
+
export declare const now: (offset?: number | null | undefined, unit?: ModifyDateUnit) => Date;
|
|
10
|
+
export declare const modifyDate: (date: Date, offset: number | null | undefined, unit?: ModifyDateUnit) => Date;
|
|
11
|
+
export declare const removeDate: (d: Date) => Date;
|
|
12
|
+
export declare const removeTime: (d: Date) => Date;
|
|
1
13
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @param data - The data structure to transform (cloned before mutation).
|
|
9
|
-
* @param paths - Slash-delimited paths to fields that should be converted.
|
|
10
|
-
* @returns A deep clone of `data` with the targeted fields converted to `Date`.
|
|
14
|
+
* Returns a Date in UTC in the allowed window (23:00–06:00).
|
|
15
|
+
* Strategy:
|
|
16
|
+
* - base = now + days
|
|
17
|
+
* - if base hour in [0..5] => keep base (rounded up to next 5 min)
|
|
18
|
+
* - if base hour in [23] => keep base (rounded up to next 5 min)
|
|
19
|
+
* - else => task at 23:30:00 UTC same date as base
|
|
11
20
|
*/
|
|
12
|
-
export declare const
|
|
13
|
-
/**
|
|
14
|
-
* Deeply converts date-like fields to raw {@link FirebaseTimestampRaw} objects.
|
|
15
|
-
*
|
|
16
|
-
* @remarks
|
|
17
|
-
* Accepts JavaScript `Date` objects, numeric millisecond values, and Firestore
|
|
18
|
-
* document objects with `_seconds`/`_nanoseconds` fields. Path segments follow
|
|
19
|
-
* the same convention as {@link toDatesDeep}.
|
|
20
|
-
*
|
|
21
|
-
* @param data - The data structure to transform (cloned before mutation).
|
|
22
|
-
* @param paths - Slash-delimited paths to fields that should be converted.
|
|
23
|
-
* @returns A deep clone of `data` with the targeted fields converted to {@link FirebaseTimestampRaw}.
|
|
24
|
-
*/
|
|
25
|
-
export declare const toTimestampsDeep: <T>(data: T, paths: string[]) => T;
|
|
21
|
+
export declare const computeScheduleTimeUtc: (base: Date, hoursFrom: number, hoursTo: number) => Date;
|
|
26
22
|
//# sourceMappingURL=helper.date.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.date.d.ts","sourceRoot":"","sources":["../../src/helper/helper.date.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helper.date.d.ts","sourceRoot":"","sources":["../../src/helper/helper.date.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACxB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,IAAI,SAAS;CACd;AAED,eAAO,MAAM,QAAQ,GACnB,SAAQ,MAAM,GAAG,IAAI,GAAG,SAAa,EACrC,OAAM,cAAoC,SACqB,CAAC;AAElE,eAAO,MAAM,KAAK,GAChB,SAAQ,MAAM,GAAG,IAAI,GAAG,SAAa,EACrC,OAAM,cAAoC,SACS,CAAC;AAEtD,eAAO,MAAM,GAAG,GACd,SAAQ,MAAM,GAAG,IAAI,GAAG,SAAa,EACrC,OAAM,cAAoC,SACH,CAAC;AAE1C,eAAO,MAAM,UAAU,GACrB,MAAM,IAAI,EACV,QAAQ,MAAM,GAAG,IAAI,GAAG,SAAS,EACjC,OAAM,cAAoC,KACzC,IAwBF,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,GAAG,IAAI,KAAG,IAKpC,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,GAAG,IAAI,KAAG,IAMpC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GACjC,MAAM,IAAI,EACV,WAAW,MAAM,EACjB,SAAS,MAAM,KACd,IAmBF,CAAC"}
|
|
@@ -1,74 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (current === "*") {
|
|
29
|
-
if (Array.isArray(obj))
|
|
30
|
-
for (const item of obj)
|
|
31
|
-
_applyPath(item, rest, convert);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (rest.length === 0) {
|
|
35
|
-
if (obj[current] !== undefined)
|
|
36
|
-
obj[current] = convert(obj[current]);
|
|
37
|
-
return;
|
|
1
|
+
export var ModifyDateUnit;
|
|
2
|
+
(function (ModifyDateUnit) {
|
|
3
|
+
ModifyDateUnit["seconds"] = "seconds";
|
|
4
|
+
ModifyDateUnit["minutes"] = "minutes";
|
|
5
|
+
ModifyDateUnit["hours"] = "hours";
|
|
6
|
+
ModifyDateUnit["days"] = "days";
|
|
7
|
+
})(ModifyDateUnit || (ModifyDateUnit = {}));
|
|
8
|
+
export const date1970 = (offset = 0, unit = ModifyDateUnit.days) => modifyDate(removeTime(removeDate(new Date())), offset, unit);
|
|
9
|
+
export const today = (offset = 0, unit = ModifyDateUnit.days) => modifyDate(removeDate(new Date()), offset, unit);
|
|
10
|
+
export const now = (offset = 0, unit = ModifyDateUnit.days) => modifyDate(new Date(), offset, unit);
|
|
11
|
+
export const modifyDate = (date, offset, unit = ModifyDateUnit.days) => {
|
|
12
|
+
offset ??= 0;
|
|
13
|
+
switch (unit) {
|
|
14
|
+
case ModifyDateUnit.days:
|
|
15
|
+
date.setUTCDate(date.getUTCDate() + offset);
|
|
16
|
+
break;
|
|
17
|
+
case ModifyDateUnit.hours:
|
|
18
|
+
date.setUTCHours(date.getUTCHours() + offset);
|
|
19
|
+
break;
|
|
20
|
+
case ModifyDateUnit.minutes:
|
|
21
|
+
date.setUTCMinutes(date.getUTCMinutes() + offset);
|
|
22
|
+
break;
|
|
23
|
+
case ModifyDateUnit.seconds:
|
|
24
|
+
date.setUTCSeconds(date.getUTCSeconds() + offset);
|
|
25
|
+
break;
|
|
26
|
+
default:
|
|
27
|
+
break;
|
|
38
28
|
}
|
|
39
|
-
|
|
29
|
+
return date;
|
|
40
30
|
};
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
export const removeDate = (d) => {
|
|
32
|
+
d.setUTCFullYear(1970);
|
|
33
|
+
d.setUTCMonth(0);
|
|
34
|
+
d.setUTCDate(1);
|
|
35
|
+
return d;
|
|
36
|
+
};
|
|
37
|
+
export const removeTime = (d) => {
|
|
38
|
+
d.setUTCHours(0);
|
|
39
|
+
d.setUTCMinutes(0);
|
|
40
|
+
d.setUTCSeconds(0);
|
|
41
|
+
d.setUTCMilliseconds(0);
|
|
42
|
+
return d;
|
|
48
43
|
};
|
|
49
44
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @param data - The data structure to transform (cloned before mutation).
|
|
57
|
-
* @param paths - Slash-delimited paths to fields that should be converted.
|
|
58
|
-
* @returns A deep clone of `data` with the targeted fields converted to `Date`.
|
|
59
|
-
*/
|
|
60
|
-
export const toDatesDeep = (data, paths) => _convertDeep(data, paths, _normalizeDate);
|
|
61
|
-
/**
|
|
62
|
-
* Deeply converts date-like fields to raw {@link FirebaseTimestampRaw} objects.
|
|
63
|
-
*
|
|
64
|
-
* @remarks
|
|
65
|
-
* Accepts JavaScript `Date` objects, numeric millisecond values, and Firestore
|
|
66
|
-
* document objects with `_seconds`/`_nanoseconds` fields. Path segments follow
|
|
67
|
-
* the same convention as {@link toDatesDeep}.
|
|
68
|
-
*
|
|
69
|
-
* @param data - The data structure to transform (cloned before mutation).
|
|
70
|
-
* @param paths - Slash-delimited paths to fields that should be converted.
|
|
71
|
-
* @returns A deep clone of `data` with the targeted fields converted to {@link FirebaseTimestampRaw}.
|
|
45
|
+
* Returns a Date in UTC in the allowed window (23:00–06:00).
|
|
46
|
+
* Strategy:
|
|
47
|
+
* - base = now + days
|
|
48
|
+
* - if base hour in [0..5] => keep base (rounded up to next 5 min)
|
|
49
|
+
* - if base hour in [23] => keep base (rounded up to next 5 min)
|
|
50
|
+
* - else => task at 23:30:00 UTC same date as base
|
|
72
51
|
*/
|
|
73
|
-
export const
|
|
52
|
+
export const computeScheduleTimeUtc = (base, hoursFrom, hoursTo) => {
|
|
53
|
+
const d = new Date(base.getTime());
|
|
54
|
+
const hour = d.getUTCHours();
|
|
55
|
+
let inRange = false;
|
|
56
|
+
if (hoursFrom > hoursTo)
|
|
57
|
+
inRange = hour >= hoursFrom || hour < hoursTo;
|
|
58
|
+
else
|
|
59
|
+
inRange = hour >= hoursFrom && hour < hoursTo;
|
|
60
|
+
if (!inRange) {
|
|
61
|
+
d.setUTCHours(hoursFrom, 0, 0, 0);
|
|
62
|
+
return d;
|
|
63
|
+
}
|
|
64
|
+
// Round up to next 5 minutes to avoid "task in the past by milliseconds" issues
|
|
65
|
+
const ms = d.getTime();
|
|
66
|
+
const fiveMin = 5 * 60 * 1000;
|
|
67
|
+
const rounded = Math.ceil(ms / fiveMin) * fiveMin;
|
|
68
|
+
return new Date(rounded);
|
|
69
|
+
};
|
|
74
70
|
//# sourceMappingURL=helper.date.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.date.js","sourceRoot":"","sources":["../../src/helper/helper.date.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"helper.date.js","sourceRoot":"","sources":["../../src/helper/helper.date.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,qCAAmB,CAAA;IACnB,qCAAmB,CAAA;IACnB,iCAAe,CAAA;IACf,+BAAa,CAAA;AACf,CAAC,EALW,cAAc,KAAd,cAAc,QAKzB;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,SAAoC,CAAC,EACrC,OAAuB,cAAc,CAAC,IAAI,EAC1C,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,EAAE,MAA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AAO,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deeply converts Firestore timestamp fields to JavaScript `Date` objects.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Path segments are separated by "/" and a wildcard may be used
|
|
6
|
+
* to iterate over array elements (e.g. "items/{wildcard}/createdAt").
|
|
7
|
+
*
|
|
8
|
+
* @param data - The data structure to transform (cloned before mutation).
|
|
9
|
+
* @param paths - Slash-delimited paths to fields that should be converted.
|
|
10
|
+
* @returns A deep clone of `data` with the targeted fields converted to `Date`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const toDatesDeep: <T>(data: T, paths: string[]) => T;
|
|
13
|
+
/**
|
|
14
|
+
* Deeply converts date-like fields to raw {@link FirebaseTimestampRaw} objects.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Accepts JavaScript `Date` objects, numeric millisecond values, and Firestore
|
|
18
|
+
* document objects with `_seconds`/`_nanoseconds` fields. Path segments follow
|
|
19
|
+
* the same convention as {@link toDatesDeep}.
|
|
20
|
+
*
|
|
21
|
+
* @param data - The data structure to transform (cloned before mutation).
|
|
22
|
+
* @param paths - Slash-delimited paths to fields that should be converted.
|
|
23
|
+
* @returns A deep clone of `data` with the targeted fields converted to {@link FirebaseTimestampRaw}.
|
|
24
|
+
*/
|
|
25
|
+
export declare const toTimestampsDeep: <T>(data: T, paths: string[]) => T;
|
|
26
|
+
//# sourceMappingURL=helper.timestamp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.timestamp.d.ts","sourceRoot":"","sources":["../../src/helper/helper.timestamp.ts"],"names":[],"mappings":"AA8DA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,MAAM,EAAE,KAAG,CACf,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,MAAM,EAAE,KAAG,CACf,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { FirebaseTimestamp, } from "./FirebaseTimestamp.js";
|
|
2
|
+
const _normalizeDate = (value) => !value
|
|
3
|
+
? value
|
|
4
|
+
: typeof value?.toDate === "function"
|
|
5
|
+
? value.toDate()
|
|
6
|
+
: value?._seconds !== undefined
|
|
7
|
+
? new Date(value._seconds * 1000 + value._nanoseconds / 1e6)
|
|
8
|
+
: typeof value === "string"
|
|
9
|
+
? new Date(value)
|
|
10
|
+
: value;
|
|
11
|
+
const _normalizeTimestamp = (value) => {
|
|
12
|
+
if (value instanceof Date)
|
|
13
|
+
return FirebaseTimestamp.fromDate(value).raw;
|
|
14
|
+
if (typeof value === "number")
|
|
15
|
+
return FirebaseTimestamp.fromMillis(value).raw;
|
|
16
|
+
if (typeof value === "object")
|
|
17
|
+
return FirebaseTimestamp.fromDoc(value)?.raw ?? null;
|
|
18
|
+
if (typeof value === "string")
|
|
19
|
+
return FirebaseTimestamp.fromIso(value).raw;
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
const _applyPath = (
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
obj, pathParts, convert) => {
|
|
25
|
+
if (!obj)
|
|
26
|
+
return;
|
|
27
|
+
const [current, ...rest] = pathParts;
|
|
28
|
+
if (current === "*") {
|
|
29
|
+
if (Array.isArray(obj))
|
|
30
|
+
for (const item of obj)
|
|
31
|
+
_applyPath(item, rest, convert);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (rest.length === 0) {
|
|
35
|
+
if (obj[current] !== undefined)
|
|
36
|
+
obj[current] = convert(obj[current]);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
_applyPath(obj[current], rest, convert);
|
|
40
|
+
};
|
|
41
|
+
const _convertDeep = (data, paths, convert) => {
|
|
42
|
+
if (Array.isArray(data))
|
|
43
|
+
return data.map((item) => _convertDeep(item, paths, convert));
|
|
44
|
+
const clone = structuredClone(data);
|
|
45
|
+
for (const path of paths)
|
|
46
|
+
_applyPath(clone, path.split("/"), convert);
|
|
47
|
+
return clone;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Deeply converts Firestore timestamp fields to JavaScript `Date` objects.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* Path segments are separated by "/" and a wildcard may be used
|
|
54
|
+
* to iterate over array elements (e.g. "items/{wildcard}/createdAt").
|
|
55
|
+
*
|
|
56
|
+
* @param data - The data structure to transform (cloned before mutation).
|
|
57
|
+
* @param paths - Slash-delimited paths to fields that should be converted.
|
|
58
|
+
* @returns A deep clone of `data` with the targeted fields converted to `Date`.
|
|
59
|
+
*/
|
|
60
|
+
export const toDatesDeep = (data, paths) => _convertDeep(data, paths, _normalizeDate);
|
|
61
|
+
/**
|
|
62
|
+
* Deeply converts date-like fields to raw {@link FirebaseTimestampRaw} objects.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* Accepts JavaScript `Date` objects, numeric millisecond values, and Firestore
|
|
66
|
+
* document objects with `_seconds`/`_nanoseconds` fields. Path segments follow
|
|
67
|
+
* the same convention as {@link toDatesDeep}.
|
|
68
|
+
*
|
|
69
|
+
* @param data - The data structure to transform (cloned before mutation).
|
|
70
|
+
* @param paths - Slash-delimited paths to fields that should be converted.
|
|
71
|
+
* @returns A deep clone of `data` with the targeted fields converted to {@link FirebaseTimestampRaw}.
|
|
72
|
+
*/
|
|
73
|
+
export const toTimestampsDeep = (data, paths) => _convertDeep(data, paths, _normalizeTimestamp);
|
|
74
|
+
//# sourceMappingURL=helper.timestamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.timestamp.js","sourceRoot":"","sources":["../../src/helper/helper.timestamp.ts"],"names":[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AAO,EAAE,KAAe,EAAK,EAAE,CACjE,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC"}
|
package/dist/helper/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helper/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helper/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC"}
|
package/dist/helper/index.js
CHANGED
package/dist/helper/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helper/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helper/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC"}
|