@nu-art/ts-common 0.202.1 → 0.202.3
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/db/types.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type Proto_DB_Object<T extends DB_Object, GeneratedKeys extends keyof T |
|
|
|
33
33
|
export type DBProto<P extends Proto_DB_Object<any, any, any, any, any>, ModifiableSubType = Omit<P['type'], P['generatedKeys'] | keyof DB_Object>, GeneratedSubType = SubsetObjectByKeys<P['type'], P['generatedKeys']>> = {
|
|
34
34
|
uiType: ModifiableSubType & Partial<GeneratedSubType> & Partial<DB_Object>;
|
|
35
35
|
dbType: P['type'];
|
|
36
|
-
generatedPropsValidator: ValidatorTypeResolver<GeneratedSubType
|
|
36
|
+
generatedPropsValidator: ValidatorTypeResolver<Omit<GeneratedSubType, keyof DB_Object>>;
|
|
37
37
|
modifiablePropsValidator: ValidatorTypeResolver<ModifiableSubType>;
|
|
38
38
|
uniqueKeys: P['uniqueKeys'][];
|
|
39
39
|
generatedProps: P['generatedKeys'][];
|
|
@@ -2,6 +2,7 @@ export declare class MemStorage {
|
|
|
2
2
|
private readonly cache;
|
|
3
3
|
constructor();
|
|
4
4
|
init<R>(makeItContext: () => Promise<R>): Promise<R>;
|
|
5
|
+
initSync<R>(makeItContext: () => R): R;
|
|
5
6
|
private set;
|
|
6
7
|
private get;
|
|
7
8
|
}
|
|
@@ -14,4 +15,5 @@ export declare class MemKey<T> {
|
|
|
14
15
|
resolve: (storage: MemStorage) => Promise<void>;
|
|
15
16
|
get: (value?: T) => T;
|
|
16
17
|
set: (value: T) => T;
|
|
18
|
+
merge: (value: T) => any;
|
|
17
19
|
}
|
|
@@ -41,6 +41,9 @@ class MemStorage {
|
|
|
41
41
|
return asyncLocalStorage.run(this, makeItContext);
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
+
initSync(makeItContext) {
|
|
45
|
+
return asyncLocalStorage.run(this, makeItContext);
|
|
46
|
+
}
|
|
44
47
|
}
|
|
45
48
|
exports.MemStorage = MemStorage;
|
|
46
49
|
class MemKey {
|
|
@@ -70,6 +73,11 @@ class MemKey {
|
|
|
70
73
|
// @ts-ignore
|
|
71
74
|
return asyncLocalStorage.getStore().set(this, value);
|
|
72
75
|
};
|
|
76
|
+
this.merge = (value) => {
|
|
77
|
+
const currentValue = this.get();
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
return asyncLocalStorage.getStore().set(this, merge(currentValue, value));
|
|
80
|
+
};
|
|
73
81
|
this.key = key;
|
|
74
82
|
this.unique = unique;
|
|
75
83
|
}
|
package/package.json
CHANGED
package/utils/date-time-tools.js
CHANGED
|
@@ -135,7 +135,7 @@ const DateTimeFormat = (format) => {
|
|
|
135
135
|
};
|
|
136
136
|
exports.DateTimeFormat = DateTimeFormat;
|
|
137
137
|
function isSameDay(date1, date2) {
|
|
138
|
-
return moment(date1).isSame(date2);
|
|
138
|
+
return moment(date1).isSame(date2, 'day');
|
|
139
139
|
}
|
|
140
140
|
exports.isSameDay = isSameDay;
|
|
141
141
|
function deltaDays(d1, d2) {
|
|
@@ -146,8 +146,8 @@ function deltaDays(d1, d2) {
|
|
|
146
146
|
return 0;
|
|
147
147
|
const millis1 = typeof d1 === 'number' ? d1 : d1.getTime();
|
|
148
148
|
const millis2 = typeof d2 === 'number' ? d2 : d2.getTime();
|
|
149
|
-
const days = (millis1 - millis2) / exports.Day;
|
|
150
|
-
//If date2 + the amount of days calculated actually lands on the same day as
|
|
149
|
+
const days = Math.floor((millis1 - millis2) / exports.Day);
|
|
150
|
+
//If date2 + the amount of days calculated actually lands on the same day as date1, return days
|
|
151
151
|
//Else, an extra day needs to be given
|
|
152
152
|
const date2Offset = new Date(date2.getTime() + (days * exports.Day));
|
|
153
153
|
return isSameDay(date1, date2Offset) ? days : days + 1;
|