@timothyw/pat-common 1.0.46 → 1.0.47
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/types/api/habits/create-habit-entry-types.d.ts +5 -5
- package/dist/types/api/habits/create-habit-entry-types.js +1 -1
- package/dist/types/misc-types.d.ts +1 -1
- package/dist/types/misc-types.js +2 -2
- package/dist/types/models/habit-data.js +6 -5
- package/package.json +1 -1
- package/src/types/api/habits/create-habit-entry-types.ts +3 -3
- package/src/types/misc-types.ts +2 -1
- package/src/types/models/habit-data.ts +7 -6
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { DateString } from "../../misc-types";
|
|
3
2
|
import { Habit } from "../../models";
|
|
3
|
+
import { DateString } from "../../misc-types";
|
|
4
4
|
export declare const createHabitEntryRequestSchema: z.ZodObject<{
|
|
5
|
-
|
|
5
|
+
dateString: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>;
|
|
6
6
|
status: z.ZodEnum<["completed", "excused"]>;
|
|
7
7
|
}, "strip", z.ZodTypeAny, {
|
|
8
|
-
date: Date;
|
|
9
8
|
status: "completed" | "excused";
|
|
9
|
+
dateString: Date;
|
|
10
10
|
}, {
|
|
11
|
-
date: string;
|
|
12
11
|
status: "completed" | "excused";
|
|
12
|
+
dateString: string;
|
|
13
13
|
}>;
|
|
14
14
|
export interface CreateHabitEntryRequest {
|
|
15
|
-
|
|
15
|
+
dateString: DateString;
|
|
16
16
|
status: 'completed' | 'excused';
|
|
17
17
|
}
|
|
18
18
|
export interface CreateHabitEntryResponse {
|
|
@@ -4,6 +4,6 @@ exports.createHabitEntryRequestSchema = void 0;
|
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const misc_types_1 = require("../../misc-types");
|
|
6
6
|
exports.createHabitEntryRequestSchema = zod_1.z.object({
|
|
7
|
-
|
|
7
|
+
dateString: misc_types_1.dateStringSchema,
|
|
8
8
|
status: zod_1.z.enum(['completed', 'excused'])
|
|
9
9
|
});
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
export type DateString = string & {
|
|
3
3
|
readonly __brand: "DateString";
|
|
4
4
|
};
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const dateStringSchema: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>;
|
|
6
6
|
export type ToDateString<T> = {
|
|
7
7
|
[K in keyof T]: T[K] extends Date ? DateString : T[K] extends Array<infer U> ? Array<ToDateString<U>> : T[K] extends object ? ToDateString<T[K]> : T[K];
|
|
8
8
|
};
|
package/dist/types/misc-types.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.dateStringSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
exports.
|
|
5
|
+
exports.dateStringSchema = zod_1.z.string()
|
|
6
6
|
.refine(val => !isNaN(Date.parse(val)), {
|
|
7
7
|
message: "Invalid date string",
|
|
8
8
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toHabit = exports.HabitEntryStatus = exports.HabitFrequency = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
4
5
|
var HabitFrequency;
|
|
5
6
|
(function (HabitFrequency) {
|
|
6
7
|
HabitFrequency["DAILY"] = "daily";
|
|
@@ -17,13 +18,13 @@ var HabitEntryStatus;
|
|
|
17
18
|
const toHabit = (data, entries, stats) => {
|
|
18
19
|
return {
|
|
19
20
|
...data,
|
|
20
|
-
createdAt: data.createdAt
|
|
21
|
-
updatedAt: data.updatedAt
|
|
21
|
+
createdAt: (0, utils_1.toDateString)(data.createdAt),
|
|
22
|
+
updatedAt: (0, utils_1.toDateString)(data.updatedAt),
|
|
22
23
|
entries: entries.map(entry => ({
|
|
23
24
|
...entry,
|
|
24
|
-
date: entry.date
|
|
25
|
-
createdAt: entry.createdAt
|
|
26
|
-
updatedAt: entry.updatedAt
|
|
25
|
+
date: (0, utils_1.toDateString)(entry.date),
|
|
26
|
+
createdAt: (0, utils_1.toDateString)(entry.createdAt),
|
|
27
|
+
updatedAt: (0, utils_1.toDateString)(entry.updatedAt)
|
|
27
28
|
})),
|
|
28
29
|
stats
|
|
29
30
|
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { dateSchema, DateString } from "../../misc-types";
|
|
3
2
|
import { Habit } from "../../models";
|
|
3
|
+
import { DateString, dateStringSchema } from "../../misc-types";
|
|
4
4
|
|
|
5
5
|
export const createHabitEntryRequestSchema = z.object({
|
|
6
|
-
|
|
6
|
+
dateString: dateStringSchema,
|
|
7
7
|
status: z.enum(['completed', 'excused'])
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
export interface CreateHabitEntryRequest {
|
|
11
|
-
|
|
11
|
+
dateString: DateString;
|
|
12
12
|
status: 'completed' | 'excused';
|
|
13
13
|
}
|
|
14
14
|
|
package/src/types/misc-types.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
3
|
export type DateString = string & { readonly __brand: "DateString" };
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
export const dateStringSchema = z.string()
|
|
5
6
|
.refine(val => !isNaN(Date.parse(val)), {
|
|
6
7
|
message: "Invalid date string",
|
|
7
8
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ToDateString } from "../misc-types";
|
|
2
|
+
import { toDateString } from "../../utils";
|
|
2
3
|
|
|
3
4
|
export enum HabitFrequency {
|
|
4
5
|
DAILY = 'daily',
|
|
@@ -51,13 +52,13 @@ export type Habit = ToDateString<HabitData> & {
|
|
|
51
52
|
export const toHabit = (data: HabitData, entries: HabitEntryData[], stats: HabitStats): Habit => {
|
|
52
53
|
return {
|
|
53
54
|
...data,
|
|
54
|
-
createdAt: data.createdAt
|
|
55
|
-
updatedAt: data.updatedAt
|
|
55
|
+
createdAt: toDateString(data.createdAt),
|
|
56
|
+
updatedAt: toDateString(data.updatedAt),
|
|
56
57
|
entries: entries.map(entry => ({
|
|
57
58
|
...entry,
|
|
58
|
-
date: entry.date
|
|
59
|
-
createdAt: entry.createdAt
|
|
60
|
-
updatedAt: entry.updatedAt
|
|
59
|
+
date: toDateString(entry.date),
|
|
60
|
+
createdAt: toDateString(entry.createdAt),
|
|
61
|
+
updatedAt: toDateString(entry.updatedAt)
|
|
61
62
|
})),
|
|
62
63
|
stats
|
|
63
64
|
};
|