@timothyw/pat-common 1.0.45 → 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.
@@ -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
- date: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>;
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
- date: DateString;
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
- date: misc_types_1.dateSchema,
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 dateSchema: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>;
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
  };
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dateSchema = void 0;
3
+ exports.dateStringSchema = void 0;
4
4
  const zod_1 = require("zod");
5
- exports.dateSchema = zod_1.z.string()
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.toISOString(),
21
- updatedAt: data.updatedAt.toISOString(),
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.toISOString(),
25
- createdAt: entry.createdAt.toISOString(),
26
- updatedAt: entry.updatedAt.toISOString()
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
  };
@@ -1,2 +1,3 @@
1
1
  import { DateString } from "../types";
2
2
  export declare const toDateString: (date: Date) => DateString;
3
+ export declare const fromDateString: (dateString: DateString) => Date;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toDateString = void 0;
3
+ exports.fromDateString = exports.toDateString = void 0;
4
4
  const toDateString = (date) => {
5
5
  return date.toISOString();
6
6
  };
7
7
  exports.toDateString = toDateString;
8
+ const fromDateString = (dateString) => {
9
+ return new Date(dateString);
10
+ };
11
+ exports.fromDateString = fromDateString;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@timothyw/pat-common",
3
3
  "description": "",
4
4
  "author": "Timothy Washburn",
5
- "version": "1.0.45",
5
+ "version": "1.0.47",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "scripts": {
@@ -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
- date: dateSchema,
6
+ dateString: dateStringSchema,
7
7
  status: z.enum(['completed', 'excused'])
8
8
  });
9
9
 
10
10
  export interface CreateHabitEntryRequest {
11
- date: DateString;
11
+ dateString: DateString;
12
12
  status: 'completed' | 'excused';
13
13
  }
14
14
 
@@ -1,7 +1,8 @@
1
1
  import { z } from "zod";
2
2
 
3
3
  export type DateString = string & { readonly __brand: "DateString" };
4
- export const dateSchema = z.string()
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 { DateString, ToDateString } from "../misc-types";
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.toISOString() as DateString,
55
- updatedAt: data.updatedAt.toISOString() as DateString,
55
+ createdAt: toDateString(data.createdAt),
56
+ updatedAt: toDateString(data.updatedAt),
56
57
  entries: entries.map(entry => ({
57
58
  ...entry,
58
- date: entry.date.toISOString() as DateString,
59
- createdAt: entry.createdAt.toISOString() as DateString,
60
- updatedAt: entry.updatedAt.toISOString() as DateString
59
+ date: toDateString(entry.date),
60
+ createdAt: toDateString(entry.createdAt),
61
+ updatedAt: toDateString(entry.updatedAt)
61
62
  })),
62
63
  stats
63
64
  };
@@ -2,4 +2,8 @@ import { DateString } from "../types";
2
2
 
3
3
  export const toDateString = (date: Date): DateString => {
4
4
  return date.toISOString() as DateString;
5
+ }
6
+
7
+ export const fromDateString = (dateString: DateString): Date => {
8
+ return new Date(dateString);
5
9
  }