@timothyw/pat-common 1.0.80 → 1.0.82

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,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?: {
@@ -10,14 +10,14 @@ export declare const createHabitRequestSchema: z.ZodObject<{
10
10
  name: string;
11
11
  frequency: HabitFrequency;
12
12
  rolloverTime: string;
13
- description?: string | undefined;
14
13
  notes?: string | undefined;
14
+ description?: string | undefined;
15
15
  }, {
16
16
  name: string;
17
17
  frequency: HabitFrequency;
18
18
  rolloverTime: string;
19
- description?: string | undefined;
20
19
  notes?: string | undefined;
20
+ description?: string | undefined;
21
21
  }>;
22
22
  export type CreateHabitRequest = z.infer<typeof createHabitRequestSchema>;
23
23
  export interface CreateHabitResponse {
@@ -8,14 +8,14 @@ export declare const updateHabitRequestSchema: z.ZodObject<{
8
8
  rolloverTime: z.ZodOptional<z.ZodString>;
9
9
  }, "strip", z.ZodTypeAny, {
10
10
  name?: string | undefined;
11
- description?: string | null | undefined;
12
11
  notes?: string | null | undefined;
12
+ description?: string | null | undefined;
13
13
  frequency?: HabitFrequency | undefined;
14
14
  rolloverTime?: string | undefined;
15
15
  }, {
16
16
  name?: string | undefined;
17
- description?: string | null | undefined;
18
17
  notes?: string | null | undefined;
18
+ description?: string | null | undefined;
19
19
  frequency?: HabitFrequency | undefined;
20
20
  rolloverTime?: string | undefined;
21
21
  }>;
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { ItemData } from "../../models";
2
3
  export declare const completeItemRequestSchema: z.ZodObject<{
3
4
  completed: z.ZodBoolean;
4
5
  }, "strip", z.ZodTypeAny, {
@@ -8,11 +9,5 @@ export declare const completeItemRequestSchema: z.ZodObject<{
8
9
  }>;
9
10
  export type CompleteItemRequest = z.infer<typeof completeItemRequestSchema>;
10
11
  export interface CompleteItemResponse {
11
- item: {
12
- id: string;
13
- name: string;
14
- completed: boolean;
15
- dueDate?: string;
16
- notes?: string;
17
- };
12
+ item: ItemData;
18
13
  }
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { ItemData } from "../../models";
2
3
  export declare const createItemRequestSchema: z.ZodObject<{
3
4
  name: z.ZodString;
4
5
  dueDate: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -9,28 +10,19 @@ export declare const createItemRequestSchema: z.ZodObject<{
9
10
  }, "strip", z.ZodTypeAny, {
10
11
  name: string;
11
12
  urgent: boolean;
12
- type?: string | null | undefined;
13
- notes?: string | undefined;
14
13
  dueDate?: string | null | undefined;
14
+ notes?: string | undefined;
15
15
  category?: string | null | undefined;
16
+ type?: string | null | undefined;
16
17
  }, {
17
18
  name: string;
18
- type?: string | null | undefined;
19
- notes?: string | undefined;
20
19
  dueDate?: string | null | undefined;
20
+ notes?: string | undefined;
21
21
  urgent?: boolean | undefined;
22
22
  category?: string | null | undefined;
23
+ type?: string | null | undefined;
23
24
  }>;
24
25
  export type CreateItemRequest = z.infer<typeof createItemRequestSchema>;
25
26
  export interface CreateItemResponse {
26
- item: {
27
- id: string;
28
- name: string;
29
- dueDate?: string;
30
- notes?: string;
31
- completed: boolean;
32
- urgent: boolean;
33
- category?: string;
34
- type?: string;
35
- };
27
+ item: ItemData;
36
28
  }
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { ItemData } from "../../models";
2
3
  export declare const updateItemRequestSchema: z.ZodObject<{
3
4
  name: z.ZodOptional<z.ZodString>;
4
5
  dueDate: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodString, Date, string>>>;
@@ -7,30 +8,21 @@ export declare const updateItemRequestSchema: z.ZodObject<{
7
8
  category: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
9
  type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
9
10
  }, "strip", z.ZodTypeAny, {
10
- type?: string | null | undefined;
11
11
  name?: string | undefined;
12
- notes?: string | null | undefined;
13
12
  dueDate?: Date | null | undefined;
13
+ notes?: string | null | undefined;
14
14
  urgent?: boolean | undefined;
15
15
  category?: string | null | undefined;
16
- }, {
17
16
  type?: string | null | undefined;
17
+ }, {
18
18
  name?: string | undefined;
19
- notes?: string | null | undefined;
20
19
  dueDate?: string | null | undefined;
20
+ notes?: string | null | undefined;
21
21
  urgent?: boolean | undefined;
22
22
  category?: string | null | undefined;
23
+ type?: string | null | undefined;
23
24
  }>;
24
25
  export type UpdateItemRequest = z.infer<typeof updateItemRequestSchema>;
25
26
  export interface UpdateItemResponse {
26
- item: {
27
- id: string;
28
- name: string;
29
- dueDate?: string;
30
- notes?: string;
31
- completed: boolean;
32
- urgent: boolean;
33
- category?: string;
34
- type?: string;
35
- };
27
+ item: ItemData;
36
28
  }
@@ -7,26 +7,26 @@ export declare const createPersonRequestSchema: z.ZodObject<{
7
7
  key: z.ZodString;
8
8
  value: z.ZodString;
9
9
  }, "strip", z.ZodTypeAny, {
10
- value: string;
11
10
  key: string;
12
- }, {
13
11
  value: string;
12
+ }, {
14
13
  key: string;
14
+ value: string;
15
15
  }>, "many">>;
16
16
  notes: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodString, PersonNoteId, string>, "many">>;
17
17
  }, "strip", z.ZodTypeAny, {
18
18
  name: string;
19
19
  notes?: PersonNoteId[] | undefined;
20
20
  properties?: {
21
- value: string;
22
21
  key: string;
22
+ value: string;
23
23
  }[] | undefined;
24
24
  }, {
25
25
  name: string;
26
26
  notes?: string[] | undefined;
27
27
  properties?: {
28
- value: string;
29
28
  key: string;
29
+ value: string;
30
30
  }[] | undefined;
31
31
  }>;
32
32
  export type CreatePersonRequest = z.infer<typeof createPersonRequestSchema>;
@@ -7,25 +7,25 @@ export declare const updatePersonRequestSchema: z.ZodObject<{
7
7
  key: z.ZodString;
8
8
  value: z.ZodString;
9
9
  }, "strip", z.ZodTypeAny, {
10
- value: string;
11
10
  key: string;
12
- }, {
13
11
  value: string;
12
+ }, {
14
13
  key: string;
14
+ value: string;
15
15
  }>, "many">>;
16
16
  noteIds: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodString, PersonNoteId, string>, "many">>;
17
17
  }, "strip", z.ZodTypeAny, {
18
18
  name?: string | undefined;
19
19
  properties?: {
20
- value: string;
21
20
  key: string;
21
+ value: string;
22
22
  }[] | undefined;
23
23
  noteIds?: PersonNoteId[] | undefined;
24
24
  }, {
25
25
  name?: string | undefined;
26
26
  properties?: {
27
- value: string;
28
27
  key: string;
28
+ value: string;
29
29
  }[] | undefined;
30
30
  noteIds?: string[] | undefined;
31
31
  }>;
@@ -5,10 +5,17 @@ export interface ItemData {
5
5
  createdAt: Date;
6
6
  updatedAt: Date;
7
7
  name: string;
8
- dueDate?: Date | null;
9
- notes?: string | null;
8
+ dueDate?: Date;
9
+ notes?: string;
10
10
  completed: boolean;
11
11
  urgent: boolean;
12
- category?: string | null;
13
- type?: string | null;
12
+ category?: string;
13
+ type?: string;
14
14
  }
15
+ export type Serialized<T> = T extends Date ? string : T extends Date | undefined ? string | undefined : T extends Date | null ? string | null : T extends (infer U)[] ? Serialized<U>[] : T extends object ? {
16
+ [K in keyof T]: Serialized<T[K]>;
17
+ } : T;
18
+ export declare function serialize<T>(obj: T): Serialized<T>;
19
+ export declare function deserialize<T>(obj: Serialized<T>): T;
20
+ export declare function serializeItemData(item: ItemData): Serialized<ItemData>;
21
+ export declare function deserializeItemData(apiData: Serialized<ItemData>): ItemData;
@@ -1,2 +1,60 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serialize = serialize;
4
+ exports.deserialize = deserialize;
5
+ exports.serializeItemData = serializeItemData;
6
+ exports.deserializeItemData = deserializeItemData;
7
+ function serialize(obj) {
8
+ return serializeRecursive(obj);
9
+ }
10
+ function deserialize(obj) {
11
+ return deserializeRecursive(obj);
12
+ }
13
+ function serializeRecursive(obj) {
14
+ if (obj === null || obj === undefined) {
15
+ return obj;
16
+ }
17
+ if (obj instanceof Date) {
18
+ return obj.toISOString();
19
+ }
20
+ if (Array.isArray(obj)) {
21
+ return obj.map(item => serializeRecursive(item));
22
+ }
23
+ if (typeof obj === 'object') {
24
+ const result = {};
25
+ for (const [key, value] of Object.entries(obj)) {
26
+ result[key] = serializeRecursive(value);
27
+ }
28
+ return result;
29
+ }
30
+ return obj;
31
+ }
32
+ function deserializeRecursive(obj) {
33
+ if (obj === null || obj === undefined) {
34
+ return obj;
35
+ }
36
+ if (typeof obj === 'string' && isISODateString(obj)) {
37
+ return new Date(obj);
38
+ }
39
+ if (Array.isArray(obj)) {
40
+ return obj.map(item => deserializeRecursive(item));
41
+ }
42
+ if (typeof obj === 'object') {
43
+ const result = {};
44
+ for (const [key, value] of Object.entries(obj)) {
45
+ result[key] = deserializeRecursive(value);
46
+ }
47
+ return result;
48
+ }
49
+ return obj;
50
+ }
51
+ function isISODateString(value) {
52
+ const isoRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/;
53
+ return isoRegex.test(value) && !isNaN(Date.parse(value));
54
+ }
55
+ function serializeItemData(item) {
56
+ return serialize(item);
57
+ }
58
+ function deserializeItemData(apiData) {
59
+ return deserialize(apiData);
60
+ }
@@ -5,7 +5,7 @@ export interface TaskData {
5
5
  createdAt: Date;
6
6
  updatedAt: Date;
7
7
  name: string;
8
- notes?: string | null;
8
+ notes?: string;
9
9
  completed: boolean;
10
10
  taskListId: TaskListId;
11
11
  }
@@ -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: {
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.80",
5
+ "version": "1.0.82",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "scripts": {
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { ItemData } from "../../models";
2
3
 
3
4
  export const completeItemRequestSchema = z.object({
4
5
  completed: z.boolean()
@@ -7,11 +8,5 @@ export const completeItemRequestSchema = z.object({
7
8
  export type CompleteItemRequest = z.infer<typeof completeItemRequestSchema>;
8
9
 
9
10
  export interface CompleteItemResponse {
10
- item: {
11
- id: string;
12
- name: string;
13
- completed: boolean;
14
- dueDate?: string;
15
- notes?: string;
16
- };
11
+ item: ItemData;
17
12
  }
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { ItemData } from "../../models";
2
3
 
3
4
  export const createItemRequestSchema = z.object({
4
5
  name: z.string().min(1),
@@ -12,14 +13,5 @@ export const createItemRequestSchema = z.object({
12
13
  export type CreateItemRequest = z.infer<typeof createItemRequestSchema>;
13
14
 
14
15
  export interface CreateItemResponse {
15
- item: {
16
- id: string;
17
- name: string;
18
- dueDate?: string;
19
- notes?: string;
20
- completed: boolean;
21
- urgent: boolean;
22
- category?: string;
23
- type?: string;
24
- };
16
+ item: ItemData;
25
17
  }
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { ItemData } from "../../models";
2
3
 
3
4
  export const updateItemRequestSchema = z.object({
4
5
  name: z.string().min(1).optional(),
@@ -12,14 +13,5 @@ export const updateItemRequestSchema = z.object({
12
13
  export type UpdateItemRequest = z.infer<typeof updateItemRequestSchema>;
13
14
 
14
15
  export interface UpdateItemResponse {
15
- item: {
16
- id: string;
17
- name: string;
18
- dueDate?: string;
19
- notes?: string;
20
- completed: boolean;
21
- urgent: boolean;
22
- category?: string;
23
- type?: string;
24
- };
16
+ item: ItemData;
25
17
  }
@@ -7,10 +7,91 @@ export interface ItemData {
7
7
  updatedAt: Date;
8
8
 
9
9
  name: string;
10
- dueDate?: Date | null;
11
- notes?: string | null;
10
+ dueDate?: Date;
11
+ notes?: string;
12
12
  completed: boolean;
13
13
  urgent: boolean;
14
- category?: string | null;
15
- type?: string | null;
14
+ category?: string;
15
+ type?: string;
16
+ }
17
+
18
+ export type Serialized<T> = T extends Date
19
+ ? string
20
+ : T extends Date | undefined
21
+ ? string | undefined
22
+ : T extends Date | null
23
+ ? string | null
24
+ : T extends (infer U)[]
25
+ ? Serialized<U>[]
26
+ : T extends object
27
+ ? { [K in keyof T]: Serialized<T[K]> }
28
+ : T;
29
+
30
+ export function serialize<T>(obj: T): Serialized<T> {
31
+ return serializeRecursive(obj) as Serialized<T>;
32
+ }
33
+
34
+ export function deserialize<T>(obj: Serialized<T>): T {
35
+ return deserializeRecursive(obj) as T;
36
+ }
37
+
38
+ function serializeRecursive(obj: any): any {
39
+ if (obj === null || obj === undefined) {
40
+ return obj;
41
+ }
42
+
43
+ if (obj instanceof Date) {
44
+ return obj.toISOString();
45
+ }
46
+
47
+ if (Array.isArray(obj)) {
48
+ return obj.map(item => serializeRecursive(item));
49
+ }
50
+
51
+ if (typeof obj === 'object') {
52
+ const result: any = {};
53
+ for (const [key, value] of Object.entries(obj)) {
54
+ result[key] = serializeRecursive(value);
55
+ }
56
+ return result;
57
+ }
58
+
59
+ return obj;
60
+ }
61
+
62
+ function deserializeRecursive(obj: any): any {
63
+ if (obj === null || obj === undefined) {
64
+ return obj;
65
+ }
66
+
67
+ if (typeof obj === 'string' && isISODateString(obj)) {
68
+ return new Date(obj);
69
+ }
70
+
71
+ if (Array.isArray(obj)) {
72
+ return obj.map(item => deserializeRecursive(item));
73
+ }
74
+
75
+ if (typeof obj === 'object') {
76
+ const result: any = {};
77
+ for (const [key, value] of Object.entries(obj)) {
78
+ result[key] = deserializeRecursive(value);
79
+ }
80
+ return result;
81
+ }
82
+
83
+ return obj;
84
+ }
85
+
86
+ function isISODateString(value: string): boolean {
87
+ const isoRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/;
88
+ return isoRegex.test(value) && !isNaN(Date.parse(value));
89
+ }
90
+
91
+ export function serializeItemData(item: ItemData): Serialized<ItemData> {
92
+ return serialize(item);
93
+ }
94
+
95
+ export function deserializeItemData(apiData: Serialized<ItemData>): ItemData {
96
+ return deserialize(apiData) as unknown as ItemData;
16
97
  }
@@ -6,7 +6,7 @@ export interface TaskData {
6
6
  createdAt: Date;
7
7
  updatedAt: Date;
8
8
  name: string;
9
- notes?: string | null;
9
+ notes?: string;
10
10
  completed: boolean;
11
11
  taskListId: TaskListId;
12
12
  }