@timothyw/pat-common 1.0.41 → 1.0.44

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/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './enums';
2
2
  export * from './types';
3
+ export * from './utils';
package/dist/index.js CHANGED
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./enums"), exports);
18
18
  __exportStar(require("./types"), exports);
19
+ __exportStar(require("./utils"), exports);
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { UserData } from "../../models";
3
3
  export declare const updateUserRequestSchema: z.ZodObject<{
4
+ name: z.ZodOptional<z.ZodString>;
4
5
  sandbox: z.ZodOptional<z.ZodObject<{
5
6
  discordId: z.ZodOptional<z.ZodOptional<z.ZodString>>;
6
7
  devices: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -21,7 +22,6 @@ export declare const updateUserRequestSchema: z.ZodObject<{
21
22
  pushToken?: string | undefined;
22
23
  }[] | undefined;
23
24
  }>>;
24
- name: z.ZodOptional<z.ZodString>;
25
25
  timezone: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
26
26
  config: z.ZodOptional<z.ZodObject<{
27
27
  modules: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -77,13 +77,13 @@ export declare const updateUserRequestSchema: z.ZodObject<{
77
77
  }[] | undefined;
78
78
  }>>;
79
79
  }, "strict", z.ZodTypeAny, {
80
+ name?: string | undefined;
80
81
  sandbox?: {
81
82
  discordId?: string | undefined;
82
83
  devices?: {
83
84
  pushToken?: string | undefined;
84
85
  }[] | undefined;
85
86
  } | undefined;
86
- name?: string | undefined;
87
87
  timezone?: string | undefined;
88
88
  config?: {
89
89
  agenda?: {
@@ -99,13 +99,13 @@ export declare const updateUserRequestSchema: z.ZodObject<{
99
99
  }[] | undefined;
100
100
  } | undefined;
101
101
  }, {
102
+ name?: string | undefined;
102
103
  sandbox?: {
103
104
  discordId?: string | undefined;
104
105
  devices?: {
105
106
  pushToken?: string | undefined;
106
107
  }[] | undefined;
107
108
  } | undefined;
108
- name?: string | undefined;
109
109
  timezone?: string | undefined;
110
110
  config?: {
111
111
  agenda?: {
@@ -1,19 +1,20 @@
1
1
  import { z } from "zod";
2
- import { HabitWithEntries } from "../../models/habit-data";
2
+ import { DateString } from "../../misc-types";
3
+ import { Habit } from "../../models";
3
4
  export declare const createHabitEntryRequestSchema: z.ZodObject<{
4
- date: z.ZodDate;
5
- status: z.ZodEnum<["completed", "excused", "missed"]>;
5
+ date: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>;
6
+ status: z.ZodEnum<["completed", "excused"]>;
6
7
  }, "strip", z.ZodTypeAny, {
7
- status: "completed" | "excused" | "missed";
8
8
  date: Date;
9
+ status: "completed" | "excused";
9
10
  }, {
10
- status: "completed" | "excused" | "missed";
11
- date: Date;
11
+ date: string;
12
+ status: "completed" | "excused";
12
13
  }>;
13
14
  export interface CreateHabitEntryRequest {
14
- date: Date;
15
- status: 'completed' | 'excused' | 'missed';
15
+ date: DateString;
16
+ status: 'completed' | 'excused';
16
17
  }
17
18
  export interface CreateHabitEntryResponse {
18
- habit: HabitWithEntries;
19
+ habit: Habit;
19
20
  }
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createHabitEntryRequestSchema = void 0;
4
4
  const zod_1 = require("zod");
5
+ const misc_types_1 = require("../../misc-types");
5
6
  exports.createHabitEntryRequestSchema = zod_1.z.object({
6
- date: zod_1.z.date(),
7
- status: zod_1.z.enum(['completed', 'excused', 'missed'])
7
+ date: misc_types_1.dateSchema,
8
+ status: zod_1.z.enum(['completed', 'excused'])
8
9
  });
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { HabitWithEntries } from "../../models/habit-data";
2
+ import { Habit } from "../../models/habit-data";
3
3
  export declare const createHabitRequestSchema: z.ZodObject<{
4
4
  name: z.ZodString;
5
5
  description: z.ZodOptional<z.ZodString>;
@@ -23,5 +23,5 @@ export interface CreateHabitRequest {
23
23
  rolloverTime: string;
24
24
  }
25
25
  export interface CreateHabitResponse {
26
- habit: HabitWithEntries;
26
+ habit: Habit;
27
27
  }
@@ -1,4 +1,4 @@
1
- import { HabitWithEntries } from "../../models/habit-data";
1
+ import { Habit } from "../../models/habit-data";
2
2
  export interface DeleteHabitEntryResponse {
3
- habit: HabitWithEntries;
3
+ habit: Habit;
4
4
  }
@@ -1,4 +1,4 @@
1
- import { HabitWithEntries } from "../../models/habit-data";
1
+ import { Habit } from "../../models/habit-data";
2
2
  export interface GetHabitsResponse {
3
- habits: HabitWithEntries[];
3
+ habits: Habit[];
4
4
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { HabitWithEntries } from "../../models/habit-data";
2
+ import { Habit } from "../../models";
3
3
  export declare const updateHabitRequestSchema: z.ZodObject<{
4
4
  name: z.ZodOptional<z.ZodString>;
5
5
  description: z.ZodOptional<z.ZodString>;
@@ -23,5 +23,5 @@ export interface UpdateHabitRequest {
23
23
  rolloverTime?: string;
24
24
  }
25
25
  export interface UpdateHabitResponse {
26
- habit: HabitWithEntries;
26
+ habit: Habit;
27
27
  }
@@ -7,15 +7,15 @@ export declare const updateItemRequestSchema: z.ZodObject<{
7
7
  category: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
8
  type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
9
9
  }, "strip", z.ZodTypeAny, {
10
- type?: string | null | undefined;
11
10
  name?: string | undefined;
11
+ type?: string | null | undefined;
12
12
  dueDate?: string | null | undefined;
13
13
  notes?: string | undefined;
14
14
  urgent?: boolean | undefined;
15
15
  category?: string | null | undefined;
16
16
  }, {
17
- type?: string | null | undefined;
18
17
  name?: string | undefined;
18
+ type?: string | null | undefined;
19
19
  dueDate?: string | null | undefined;
20
20
  notes?: string | undefined;
21
21
  urgent?: boolean | undefined;
@@ -3,3 +3,6 @@ export type DateString = string & {
3
3
  readonly __brand: "DateString";
4
4
  };
5
5
  export declare const dateSchema: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>;
6
+ export type ToDateString<T> = {
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
+ };
@@ -1,3 +1,4 @@
1
+ import { ToDateString } from "../misc-types";
1
2
  export declare enum HabitFrequency {
2
3
  DAILY = "daily",
3
4
  WEEKLY = "weekly",
@@ -34,7 +35,8 @@ export interface HabitStats {
34
35
  missedDays: number;
35
36
  completionRate: number;
36
37
  }
37
- export interface HabitWithEntries extends HabitData {
38
- entries: HabitEntryData[];
38
+ export type Habit = ToDateString<HabitData> & {
39
+ entries: ToDateString<HabitEntryData>[];
39
40
  stats: HabitStats;
40
- }
41
+ };
42
+ export declare const toHabit: (data: HabitData, entries: HabitEntryData[], stats: HabitStats) => Habit;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HabitEntryStatus = exports.HabitFrequency = void 0;
3
+ exports.toHabit = exports.HabitEntryStatus = exports.HabitFrequency = void 0;
4
4
  var HabitFrequency;
5
5
  (function (HabitFrequency) {
6
6
  HabitFrequency["DAILY"] = "daily";
@@ -14,3 +14,18 @@ var HabitEntryStatus;
14
14
  HabitEntryStatus["COMPLETED"] = "completed";
15
15
  HabitEntryStatus["EXCUSED"] = "excused";
16
16
  })(HabitEntryStatus || (exports.HabitEntryStatus = HabitEntryStatus = {}));
17
+ const toHabit = (data, entries, stats) => {
18
+ return {
19
+ ...data,
20
+ createdAt: data.createdAt.toISOString(),
21
+ updatedAt: data.updatedAt.toISOString(),
22
+ entries: entries.map(entry => ({
23
+ ...entry,
24
+ date: entry.date.toISOString(),
25
+ createdAt: entry.createdAt.toISOString(),
26
+ updatedAt: entry.updatedAt.toISOString()
27
+ })),
28
+ stats
29
+ };
30
+ };
31
+ exports.toHabit = toHabit;
@@ -95,13 +95,13 @@ export declare const userDataSchema: z.ZodObject<{
95
95
  };
96
96
  createdAt: Date;
97
97
  updatedAt: Date;
98
+ name: string;
98
99
  sandbox: {
99
100
  devices: {
100
101
  pushToken: string;
101
102
  }[];
102
103
  discordId?: string | undefined;
103
104
  };
104
- name: string;
105
105
  timezone: string;
106
106
  config: {
107
107
  agenda: {
@@ -120,13 +120,13 @@ export declare const userDataSchema: z.ZodObject<{
120
120
  _id: string;
121
121
  createdAt: Date;
122
122
  updatedAt: Date;
123
+ name: string;
123
124
  sandbox: {
124
125
  devices: {
125
126
  pushToken: string;
126
127
  }[];
127
128
  discordId?: string | undefined;
128
129
  };
129
- name: string;
130
130
  timezone: string;
131
131
  config: {
132
132
  agenda: {
@@ -0,0 +1,2 @@
1
+ import { DateString } from "../types";
2
+ export declare const toDateString: (date: Date) => DateString;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDateString = void 0;
4
+ const toDateString = (date) => {
5
+ return date.toISOString();
6
+ };
7
+ exports.toDateString = toDateString;
@@ -0,0 +1 @@
1
+ export * from './date-utils';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./date-utils"), exports);
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.41",
5
+ "version": "1.0.44",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "scripts": {
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './enums'
2
- export * from './types'
2
+ export * from './types'
3
+ export * from './utils'
@@ -1,16 +1,17 @@
1
1
  import { z } from "zod";
2
- import { HabitWithEntries } from "../../models/habit-data";
2
+ import { dateSchema, DateString } from "../../misc-types";
3
+ import { Habit } from "../../models";
3
4
 
4
5
  export const createHabitEntryRequestSchema = z.object({
5
- date: z.date(),
6
- status: z.enum(['completed', 'excused', 'missed'])
6
+ date: dateSchema,
7
+ status: z.enum(['completed', 'excused'])
7
8
  });
8
9
 
9
10
  export interface CreateHabitEntryRequest {
10
- date: Date;
11
- status: 'completed' | 'excused' | 'missed';
11
+ date: DateString;
12
+ status: 'completed' | 'excused';
12
13
  }
13
14
 
14
15
  export interface CreateHabitEntryResponse {
15
- habit: HabitWithEntries;
16
+ habit: Habit;
16
17
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { HabitWithEntries } from "../../models/habit-data";
2
+ import { Habit } from "../../models/habit-data";
3
3
 
4
4
  export const createHabitRequestSchema = z.object({
5
5
  name: z.string().min(1, 'Name is required').trim(),
@@ -16,5 +16,5 @@ export interface CreateHabitRequest {
16
16
  }
17
17
 
18
18
  export interface CreateHabitResponse {
19
- habit: HabitWithEntries;
19
+ habit: Habit;
20
20
  }
@@ -1,5 +1,5 @@
1
- import { HabitWithEntries } from "../../models/habit-data";
1
+ import { Habit } from "../../models/habit-data";
2
2
 
3
3
  export interface DeleteHabitEntryResponse {
4
- habit: HabitWithEntries;
4
+ habit: Habit;
5
5
  }
@@ -1,5 +1,5 @@
1
- import { HabitWithEntries } from "../../models/habit-data";
1
+ import { Habit } from "../../models/habit-data";
2
2
 
3
3
  export interface GetHabitsResponse {
4
- habits: HabitWithEntries[];
4
+ habits: Habit[];
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { HabitWithEntries } from "../../models/habit-data";
2
+ import { Habit } from "../../models";
3
3
 
4
4
  export const updateHabitRequestSchema = z.object({
5
5
  name: z.string().min(1, 'Name is required').trim().optional(),
@@ -16,5 +16,5 @@ export interface UpdateHabitRequest {
16
16
  }
17
17
 
18
18
  export interface UpdateHabitResponse {
19
- habit: HabitWithEntries;
19
+ habit: Habit;
20
20
  }
@@ -5,4 +5,14 @@ export const dateSchema = z.string()
5
5
  .refine(val => !isNaN(Date.parse(val)), {
6
6
  message: "Invalid date string",
7
7
  })
8
- .transform(val => new Date(val));
8
+ .transform(val => new Date(val));
9
+
10
+ export type ToDateString<T> = {
11
+ [K in keyof T]: T[K] extends Date
12
+ ? DateString
13
+ : T[K] extends Array<infer U>
14
+ ? Array<ToDateString<U>>
15
+ : T[K] extends object
16
+ ? ToDateString<T[K]>
17
+ : T[K];
18
+ };
@@ -1,3 +1,5 @@
1
+ import { DateString, ToDateString } from "../misc-types";
2
+
1
3
  export enum HabitFrequency {
2
4
  DAILY = 'daily',
3
5
  WEEKLY = 'weekly',
@@ -39,7 +41,22 @@ export interface HabitStats {
39
41
  completionRate: number;
40
42
  }
41
43
 
42
- export interface HabitWithEntries extends HabitData {
43
- entries: HabitEntryData[];
44
+ export type Habit = ToDateString<HabitData> & {
45
+ entries: ToDateString<HabitEntryData>[];
44
46
  stats: HabitStats;
47
+ }
48
+
49
+ export const toHabit = (data: HabitData, entries: HabitEntryData[], stats: HabitStats): Habit => {
50
+ return {
51
+ ...data,
52
+ createdAt: data.createdAt.toISOString() as DateString,
53
+ updatedAt: data.updatedAt.toISOString() as DateString,
54
+ entries: entries.map(entry => ({
55
+ ...entry,
56
+ date: entry.date.toISOString() as DateString,
57
+ createdAt: entry.createdAt.toISOString() as DateString,
58
+ updatedAt: entry.updatedAt.toISOString() as DateString
59
+ })),
60
+ stats
61
+ };
45
62
  }
@@ -0,0 +1,5 @@
1
+ import { DateString } from "../types";
2
+
3
+ export const toDateString = (date: Date): DateString => {
4
+ return date.toISOString() as DateString;
5
+ }
@@ -0,0 +1 @@
1
+ export * from './date-utils'