@timothyw/pat-common 1.0.92 → 1.0.93
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/account/get-user-types.d.ts +2 -1
- package/dist/types/api/account/update-user-types.d.ts +5 -4
- package/dist/types/api/habits/create-habit-entry-types.d.ts +3 -3
- package/dist/types/api/habits/create-habit-types.d.ts +3 -2
- package/dist/types/api/habits/create-habit-types.js +2 -2
- package/dist/types/api/habits/delete-habit-entry-types.d.ts +3 -2
- package/dist/types/api/habits/get-habits-types.d.ts +3 -2
- package/dist/types/api/habits/update-habit-types.d.ts +2 -1
- package/dist/types/api/items/complete-item-types.d.ts +2 -1
- package/dist/types/api/items/create-item-types.d.ts +4 -3
- package/dist/types/api/items/get-items-types.d.ts +2 -1
- package/dist/types/api/items/update-item-types.d.ts +4 -3
- package/dist/types/api/people/create-person-note-types.d.ts +2 -1
- package/dist/types/api/people/create-person-types.d.ts +8 -8
- package/dist/types/api/people/get-people-types.d.ts +2 -1
- package/dist/types/api/people/get-person-notes-types.d.ts +2 -1
- package/dist/types/api/people/update-person-note-types.d.ts +2 -1
- package/dist/types/api/people/update-person-types.d.ts +8 -8
- package/dist/types/api/tasks/complete-task-types.d.ts +3 -10
- package/dist/types/api/tasks/create-task-list-types.d.ts +3 -7
- package/dist/types/api/tasks/create-task-types.d.ts +4 -11
- package/dist/types/api/tasks/get-task-lists-types.d.ts +3 -7
- package/dist/types/api/tasks/get-tasks-types.d.ts +3 -10
- package/dist/types/api/tasks/update-task-list-types.d.ts +3 -7
- package/dist/types/api/tasks/update-task-types.d.ts +5 -12
- package/dist/types/api/thoughts/create-thought-types.d.ts +3 -4
- package/dist/types/api/thoughts/get-thoughts-types.d.ts +3 -4
- package/dist/types/api/thoughts/update-thought-types.d.ts +3 -4
- package/dist/types/models/item-data.d.ts +0 -7
- package/dist/types/models/item-data.js +0 -58
- package/dist/types/models/user-data.d.ts +2 -2
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/serializing-utils.d.ts +10 -0
- package/dist/utils/serializing-utils.js +60 -0
- package/package.json +1 -1
- package/src/types/api/account/get-user-types.ts +2 -1
- package/src/types/api/account/update-user-types.ts +2 -1
- package/src/types/api/habits/create-habit-entry-types.ts +3 -3
- package/src/types/api/habits/create-habit-types.ts +3 -3
- package/src/types/api/habits/delete-habit-entry-types.ts +3 -2
- package/src/types/api/habits/get-habits-types.ts +3 -2
- package/src/types/api/habits/update-habit-types.ts +2 -1
- package/src/types/api/items/complete-item-types.ts +2 -1
- package/src/types/api/items/create-item-types.ts +2 -1
- package/src/types/api/items/get-items-types.ts +2 -1
- package/src/types/api/items/update-item-types.ts +2 -1
- package/src/types/api/people/create-person-note-types.ts +3 -2
- package/src/types/api/people/create-person-types.ts +4 -3
- package/src/types/api/people/get-people-types.ts +3 -3
- package/src/types/api/people/get-person-notes-types.ts +3 -3
- package/src/types/api/people/update-person-note-types.ts +3 -3
- package/src/types/api/people/update-person-types.ts +4 -3
- package/src/types/api/tasks/complete-task-types.ts +3 -10
- package/src/types/api/tasks/create-task-list-types.ts +3 -7
- package/src/types/api/tasks/create-task-types.ts +4 -10
- package/src/types/api/tasks/get-task-lists-types.ts +3 -7
- package/src/types/api/tasks/get-tasks-types.ts +3 -10
- package/src/types/api/tasks/update-task-list-types.ts +3 -7
- package/src/types/api/tasks/update-task-types.ts +4 -10
- package/src/types/api/thoughts/create-thought-types.ts +3 -4
- package/src/types/api/thoughts/get-thoughts-types.ts +4 -4
- package/src/types/api/thoughts/update-thought-types.ts +3 -4
- package/src/types/id-types.ts +0 -1
- package/src/types/models/item-data.ts +0 -81
- package/src/utils/index.ts +2 -1
- package/src/utils/serializing-utils.ts +84 -0
|
@@ -95,13 +95,13 @@ export declare const userDataSchema: z.ZodObject<{
|
|
|
95
95
|
};
|
|
96
96
|
createdAt: Date;
|
|
97
97
|
updatedAt: Date;
|
|
98
|
-
name: string;
|
|
99
98
|
sandbox: {
|
|
100
99
|
devices: {
|
|
101
100
|
pushToken: string;
|
|
102
101
|
}[];
|
|
103
102
|
discordId?: string | undefined;
|
|
104
103
|
};
|
|
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;
|
|
124
123
|
sandbox: {
|
|
125
124
|
devices: {
|
|
126
125
|
pushToken: string;
|
|
127
126
|
}[];
|
|
128
127
|
discordId?: string | undefined;
|
|
129
128
|
};
|
|
129
|
+
name: string;
|
|
130
130
|
timezone: string;
|
|
131
131
|
config: {
|
|
132
132
|
agenda: {
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ItemData } from "../types";
|
|
2
|
+
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 ? {
|
|
3
|
+
[K in keyof T]: Serialized<T[K]>;
|
|
4
|
+
} : T;
|
|
5
|
+
export declare class Serializer {
|
|
6
|
+
static serialize<T>(obj: T): Serialized<T>;
|
|
7
|
+
static deserialize<T>(obj: Serialized<T>): T;
|
|
8
|
+
static serializeItemData(item: ItemData): Serialized<ItemData>;
|
|
9
|
+
static deserializeItemData(apiData: Serialized<ItemData>): ItemData;
|
|
10
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Serializer = void 0;
|
|
4
|
+
class Serializer {
|
|
5
|
+
static serialize(obj) {
|
|
6
|
+
return serializeRecursive(obj);
|
|
7
|
+
}
|
|
8
|
+
static deserialize(obj) {
|
|
9
|
+
return deserializeRecursive(obj);
|
|
10
|
+
}
|
|
11
|
+
static serializeItemData(item) {
|
|
12
|
+
return this.serialize(item);
|
|
13
|
+
}
|
|
14
|
+
static deserializeItemData(apiData) {
|
|
15
|
+
return this.deserialize(apiData);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.Serializer = Serializer;
|
|
19
|
+
function serializeRecursive(obj) {
|
|
20
|
+
if (obj === null || obj === undefined) {
|
|
21
|
+
return obj;
|
|
22
|
+
}
|
|
23
|
+
if (obj instanceof Date) {
|
|
24
|
+
return obj.toISOString();
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(obj)) {
|
|
27
|
+
return obj.map(item => serializeRecursive(item));
|
|
28
|
+
}
|
|
29
|
+
if (typeof obj === 'object') {
|
|
30
|
+
const result = {};
|
|
31
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
32
|
+
result[key] = serializeRecursive(value);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
return obj;
|
|
37
|
+
}
|
|
38
|
+
function deserializeRecursive(obj) {
|
|
39
|
+
if (obj === null || obj === undefined) {
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
42
|
+
if (typeof obj === 'string' && isISODateString(obj)) {
|
|
43
|
+
return new Date(obj);
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(obj)) {
|
|
46
|
+
return obj.map(item => deserializeRecursive(item));
|
|
47
|
+
}
|
|
48
|
+
if (typeof obj === 'object') {
|
|
49
|
+
const result = {};
|
|
50
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
51
|
+
result[key] = deserializeRecursive(value);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
return obj;
|
|
56
|
+
}
|
|
57
|
+
function isISODateString(value) {
|
|
58
|
+
const isoRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/;
|
|
59
|
+
return isoRegex.test(value) && !isNaN(Date.parse(value));
|
|
60
|
+
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { UserData, userDataSchema } from "../../models";
|
|
3
|
+
import { Serialized } from "../../../utils";
|
|
3
4
|
|
|
4
5
|
export const updateUserRequestSchema = userDataSchema
|
|
5
6
|
.omit({ _id: true, createdAt: true, updatedAt: true })
|
|
@@ -9,5 +10,5 @@ export const updateUserRequestSchema = userDataSchema
|
|
|
9
10
|
export type UpdateUserRequest = z.infer<typeof updateUserRequestSchema>;
|
|
10
11
|
|
|
11
12
|
export interface UpdateUserResponse {
|
|
12
|
-
user: UserData
|
|
13
|
+
user: Serialized<UserData>;
|
|
13
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { Habit, HabitEntryStatus } from "../../models";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { dateOnlyStringSchema } from "../../misc-types";
|
|
4
|
+
import { Serialized } from "../../../utils";
|
|
5
5
|
|
|
6
6
|
export const createHabitEntryRequestSchema = z.object({
|
|
7
7
|
date: dateOnlyStringSchema,
|
|
@@ -11,5 +11,5 @@ export const createHabitEntryRequestSchema = z.object({
|
|
|
11
11
|
export type CreateHabitEntryRequest = z.infer<typeof createHabitEntryRequestSchema>;
|
|
12
12
|
|
|
13
13
|
export interface CreateHabitEntryResponse {
|
|
14
|
-
habit: Habit
|
|
14
|
+
habit: Serialized<Habit>;
|
|
15
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { Habit, HabitFrequency } from "../../models
|
|
3
|
-
import {
|
|
2
|
+
import { Habit, HabitFrequency } from "../../models";
|
|
3
|
+
import { Serialized } from "../../../utils";
|
|
4
4
|
|
|
5
5
|
export const createHabitRequestSchema = z.object({
|
|
6
6
|
name: z.string().min(1, 'Name is required').trim(),
|
|
@@ -13,5 +13,5 @@ export const createHabitRequestSchema = z.object({
|
|
|
13
13
|
export type CreateHabitRequest = z.infer<typeof createHabitRequestSchema>;
|
|
14
14
|
|
|
15
15
|
export interface CreateHabitResponse {
|
|
16
|
-
habit: Habit
|
|
16
|
+
habit: Serialized<Habit>;
|
|
17
17
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { Habit, HabitFrequency } from "../../models";
|
|
3
|
+
import { Serialized } from "../../../utils";
|
|
3
4
|
|
|
4
5
|
export const updateHabitRequestSchema = z.object({
|
|
5
6
|
name: z.string().min(1, 'Name is required').trim().optional(),
|
|
@@ -12,5 +13,5 @@ export const updateHabitRequestSchema = z.object({
|
|
|
12
13
|
export type UpdateHabitRequest = z.infer<typeof updateHabitRequestSchema>;
|
|
13
14
|
|
|
14
15
|
export interface UpdateHabitResponse {
|
|
15
|
-
habit: Habit
|
|
16
|
+
habit: Serialized<Habit>;
|
|
16
17
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { personIdSchema
|
|
2
|
+
import { personIdSchema } from "../../id-types";
|
|
3
3
|
import { PersonNoteData } from "../../models";
|
|
4
|
+
import { Serialized } from "../../../utils";
|
|
4
5
|
|
|
5
6
|
export const createPersonNoteRequestSchema = z.object({
|
|
6
7
|
personId: personIdSchema,
|
|
@@ -10,5 +11,5 @@ export const createPersonNoteRequestSchema = z.object({
|
|
|
10
11
|
export type CreatePersonNoteRequest = z.infer<typeof createPersonNoteRequestSchema>;
|
|
11
12
|
|
|
12
13
|
export interface CreatePersonNoteResponse {
|
|
13
|
-
personNote: PersonNoteData
|
|
14
|
+
personNote: Serialized<PersonNoteData>;
|
|
14
15
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
3
|
-
import { Person
|
|
2
|
+
import { personNoteIdSchema } from "../../id-types";
|
|
3
|
+
import { Person } from "../../models";
|
|
4
|
+
import { Serialized } from "../../../utils";
|
|
4
5
|
|
|
5
6
|
export const createPersonRequestSchema = z.object({
|
|
6
7
|
name: z.string().min(1),
|
|
@@ -14,5 +15,5 @@ export const createPersonRequestSchema = z.object({
|
|
|
14
15
|
export type CreatePersonRequest = z.infer<typeof createPersonRequestSchema>;
|
|
15
16
|
|
|
16
17
|
export interface CreatePersonResponse {
|
|
17
|
-
person: Person
|
|
18
|
+
person: Serialized<Person>;
|
|
18
19
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Person } from "../../models";
|
|
2
|
+
import { Serialized } from "../../../utils";
|
|
3
3
|
|
|
4
4
|
export interface GetPeopleResponse {
|
|
5
|
-
people:
|
|
5
|
+
people: Serialized<Person>[];
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { PersonNoteData } from "../../models";
|
|
2
|
+
import { Serialized } from "../../../utils";
|
|
3
3
|
|
|
4
4
|
export interface GetPersonNotesResponse {
|
|
5
|
-
personNotes:
|
|
5
|
+
personNotes: Serialized<PersonNoteData>[];
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { PersonNoteData } from "../../models";
|
|
3
|
+
import { Serialized } from "../../../utils";
|
|
4
4
|
|
|
5
5
|
export const updatePersonNoteRequestSchema = z.object({
|
|
6
6
|
content: z.string().min(1)
|
|
@@ -9,5 +9,5 @@ export const updatePersonNoteRequestSchema = z.object({
|
|
|
9
9
|
export type UpdatePersonNoteRequest = z.infer<typeof updatePersonNoteRequestSchema>;
|
|
10
10
|
|
|
11
11
|
export interface UpdatePersonNoteResponse {
|
|
12
|
-
personNote: PersonNoteData
|
|
12
|
+
personNote: Serialized<PersonNoteData>;
|
|
13
13
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
3
|
-
import { Person
|
|
2
|
+
import { personNoteIdSchema } from "../../id-types";
|
|
3
|
+
import { Person } from "../../models";
|
|
4
|
+
import { Serialized } from "../../../utils";
|
|
4
5
|
|
|
5
6
|
export const updatePersonRequestSchema = z.object({
|
|
6
7
|
name: z.string().min(1).optional(),
|
|
@@ -14,5 +15,5 @@ export const updatePersonRequestSchema = z.object({
|
|
|
14
15
|
export type UpdatePersonRequest = z.infer<typeof updatePersonRequestSchema>;
|
|
15
16
|
|
|
16
17
|
export interface UpdatePersonResponse {
|
|
17
|
-
person: Person
|
|
18
|
+
person: Serialized<Person>;
|
|
18
19
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { Serialized } from "../../../utils";
|
|
3
|
+
import { TaskData } from "../../models";
|
|
3
4
|
|
|
4
5
|
export const completeTaskRequestSchema = z.object({
|
|
5
6
|
completed: z.boolean()
|
|
@@ -8,13 +9,5 @@ export const completeTaskRequestSchema = z.object({
|
|
|
8
9
|
export type CompleteTaskRequest = z.infer<typeof completeTaskRequestSchema>;
|
|
9
10
|
|
|
10
11
|
export interface CompleteTaskResponse {
|
|
11
|
-
task:
|
|
12
|
-
id: TaskId;
|
|
13
|
-
name: string;
|
|
14
|
-
notes?: string;
|
|
15
|
-
completed: boolean;
|
|
16
|
-
taskListId: string;
|
|
17
|
-
createdAt: string;
|
|
18
|
-
updatedAt: string;
|
|
19
|
-
};
|
|
12
|
+
task: Serialized<TaskData>;
|
|
20
13
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { Serialized } from "../../../utils";
|
|
3
|
+
import { TaskListData } from "../../models";
|
|
3
4
|
|
|
4
5
|
export const createTaskListRequestSchema = z.object({
|
|
5
6
|
name: z.string().min(1)
|
|
@@ -8,10 +9,5 @@ export const createTaskListRequestSchema = z.object({
|
|
|
8
9
|
export type CreateTaskListRequest = z.infer<typeof createTaskListRequestSchema>;
|
|
9
10
|
|
|
10
11
|
export interface CreateTaskListResponse {
|
|
11
|
-
taskList:
|
|
12
|
-
id: TaskListId;
|
|
13
|
-
name: string;
|
|
14
|
-
createdAt: string;
|
|
15
|
-
updatedAt: string;
|
|
16
|
-
};
|
|
12
|
+
taskList: Serialized<TaskListData>;
|
|
17
13
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { taskListIdSchema } from '../../id-types';
|
|
3
|
+
import { Serialized } from "../../../utils";
|
|
4
|
+
import { TaskData } from "../../models";
|
|
3
5
|
|
|
4
6
|
export const createTaskRequestSchema = z.object({
|
|
5
7
|
name: z.string().min(1),
|
|
@@ -10,13 +12,5 @@ export const createTaskRequestSchema = z.object({
|
|
|
10
12
|
export type CreateTaskRequest = z.infer<typeof createTaskRequestSchema>;
|
|
11
13
|
|
|
12
14
|
export interface CreateTaskResponse {
|
|
13
|
-
task:
|
|
14
|
-
id: TaskId;
|
|
15
|
-
name: string;
|
|
16
|
-
notes?: string;
|
|
17
|
-
completed: boolean;
|
|
18
|
-
taskListId: TaskListId;
|
|
19
|
-
createdAt: string;
|
|
20
|
-
updatedAt: string;
|
|
21
|
-
};
|
|
15
|
+
task: Serialized<TaskData>;
|
|
22
16
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Serialized } from "../../../utils";
|
|
2
|
+
import { TaskListData } from "../../models";
|
|
2
3
|
|
|
3
4
|
export interface GetTaskListsResponse {
|
|
4
|
-
taskLists:
|
|
5
|
-
id: TaskListId;
|
|
6
|
-
name: string;
|
|
7
|
-
createdAt: string;
|
|
8
|
-
updatedAt: string;
|
|
9
|
-
}>;
|
|
5
|
+
taskLists: Serialized<TaskListData>[];
|
|
10
6
|
}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Serialized } from "../../../utils";
|
|
2
|
+
import { TaskData } from "../../models";
|
|
2
3
|
|
|
3
4
|
export interface GetTasksResponse {
|
|
4
|
-
tasks:
|
|
5
|
-
id: TaskId;
|
|
6
|
-
name: string;
|
|
7
|
-
notes?: string;
|
|
8
|
-
completed: boolean;
|
|
9
|
-
taskListId: TaskListId;
|
|
10
|
-
createdAt: string;
|
|
11
|
-
updatedAt: string;
|
|
12
|
-
}>;
|
|
5
|
+
tasks: Serialized<TaskData>;
|
|
13
6
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { Serialized } from "../../../utils";
|
|
3
|
+
import { TaskListData } from "../../models";
|
|
3
4
|
|
|
4
5
|
export const updateTaskListRequestSchema = z.object({
|
|
5
6
|
name: z.string().min(1).optional()
|
|
@@ -8,10 +9,5 @@ export const updateTaskListRequestSchema = z.object({
|
|
|
8
9
|
export type UpdateTaskListRequest = z.infer<typeof updateTaskListRequestSchema>;
|
|
9
10
|
|
|
10
11
|
export interface UpdateTaskListResponse {
|
|
11
|
-
taskList:
|
|
12
|
-
id: TaskListId;
|
|
13
|
-
name: string;
|
|
14
|
-
createdAt: string;
|
|
15
|
-
updatedAt: string;
|
|
16
|
-
};
|
|
12
|
+
taskList: Serialized<TaskListData>;
|
|
17
13
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { taskListIdSchema } from '../../id-types';
|
|
3
|
+
import { Serialized } from "../../../utils";
|
|
4
|
+
import { TaskData } from "../../models";
|
|
3
5
|
|
|
4
6
|
export const updateTaskRequestSchema = z.object({
|
|
5
7
|
name: z.string().min(1).optional(),
|
|
@@ -11,13 +13,5 @@ export const updateTaskRequestSchema = z.object({
|
|
|
11
13
|
export type UpdateTaskRequest = z.infer<typeof updateTaskRequestSchema>;
|
|
12
14
|
|
|
13
15
|
export interface UpdateTaskResponse {
|
|
14
|
-
task:
|
|
15
|
-
id: TaskId;
|
|
16
|
-
name: string;
|
|
17
|
-
notes?: string;
|
|
18
|
-
completed: boolean;
|
|
19
|
-
taskListId: TaskListId;
|
|
20
|
-
createdAt: string;
|
|
21
|
-
updatedAt: string;
|
|
22
|
-
};
|
|
16
|
+
task: Serialized<TaskData>;
|
|
23
17
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { Serialized } from "../../../utils";
|
|
3
|
+
import { ThoughtData } from "../../models";
|
|
2
4
|
|
|
3
5
|
export const createThoughtRequestSchema = z.object({
|
|
4
6
|
content: z.string().min(1)
|
|
@@ -7,8 +9,5 @@ export const createThoughtRequestSchema = z.object({
|
|
|
7
9
|
export type CreateThoughtRequest = z.infer<typeof createThoughtRequestSchema>;
|
|
8
10
|
|
|
9
11
|
export interface CreateThoughtResponse {
|
|
10
|
-
thought:
|
|
11
|
-
id: string;
|
|
12
|
-
content: string;
|
|
13
|
-
};
|
|
12
|
+
thought: Serialized<ThoughtData>;
|
|
14
13
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { Serialized } from "../../../utils";
|
|
3
|
+
import { ThoughtData } from "../../models";
|
|
2
4
|
|
|
3
5
|
export const updateThoughtRequestSchema = z.object({
|
|
4
6
|
content: z.string().min(1)
|
|
@@ -7,8 +9,5 @@ export const updateThoughtRequestSchema = z.object({
|
|
|
7
9
|
export type UpdateThoughtRequest = z.infer<typeof updateThoughtRequestSchema>;
|
|
8
10
|
|
|
9
11
|
export interface UpdateThoughtResponse {
|
|
10
|
-
thought:
|
|
11
|
-
id: string;
|
|
12
|
-
content: string;
|
|
13
|
-
};
|
|
12
|
+
thought: Serialized<ThoughtData>;
|
|
14
13
|
}
|
package/src/types/id-types.ts
CHANGED
|
@@ -13,85 +13,4 @@ export interface ItemData {
|
|
|
13
13
|
urgent: boolean;
|
|
14
14
|
category?: string;
|
|
15
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;
|
|
97
16
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './date-utils'
|
|
1
|
+
export * from './date-utils'
|
|
2
|
+
export * from './serializing-utils'
|