@read-frog/api-contract 0.4.1 → 0.6.1

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.
@@ -0,0 +1,129 @@
1
+ import {
2
+ cardStateSchema,
3
+ fsrsReviewLogSnapshotSchema,
4
+ reviewRatingSchema,
5
+ scheduleStatusSchema,
6
+ schedulingParamsSchema,
7
+ SRS_REVIEW_DURATION_MS_MAX,
8
+ srsStepSchema,
9
+ } from "@read-frog/definitions"
10
+ import { z } from "zod"
11
+ import { cardSchema } from "./card"
12
+ import { timezoneSchema } from "./timezone"
13
+
14
+ export {
15
+ reviewRatingSchema,
16
+ schedulingParamsSchema,
17
+ SRS_REVIEW_DURATION_MS_MAX,
18
+ }
19
+ export { timezoneSchema } from "./timezone"
20
+ export type { Timezone } from "./timezone"
21
+ export type { ReviewRating, SchedulingParams } from "@read-frog/definitions"
22
+
23
+ export const stepSchema = srsStepSchema
24
+ export type Step = z.infer<typeof stepSchema>
25
+
26
+ export const SRS_REVIEW_CLIENT_ID_NAMESPACE = "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
27
+ const srsReviewClientIdNamePrefix = "readfrog:srs-review"
28
+ const nullLastReviewTimeSentinel = "null"
29
+
30
+ export interface SrsReviewClientIdCard {
31
+ id: string
32
+ lastReviewTime: Date | string | null
33
+ }
34
+
35
+ export async function createSrsReviewClientId(card: SrsReviewClientIdCard) {
36
+ return uuidV5(
37
+ `${srsReviewClientIdNamePrefix}:${card.id}:${formatLastReviewTime(card.lastReviewTime)}`,
38
+ SRS_REVIEW_CLIENT_ID_NAMESPACE,
39
+ )
40
+ }
41
+
42
+ export const srsReviewInputSchema = z.object({
43
+ cardId: z.uuid(),
44
+ id: z.uuid().optional(),
45
+ rating: reviewRatingSchema,
46
+ durationMs: z.number().int().min(0).max(SRS_REVIEW_DURATION_MS_MAX),
47
+ timezone: timezoneSchema,
48
+ }).strict()
49
+ export type SrsReviewInput = z.infer<typeof srsReviewInputSchema>
50
+
51
+ export const srsRollbackReviewInputSchema = z.object({
52
+ cardId: z.uuid(),
53
+ }).strict()
54
+ export type SrsRollbackReviewInput = z.infer<typeof srsRollbackReviewInputSchema>
55
+
56
+ export const srsRevlogSchema = z.object({
57
+ id: z.uuid(),
58
+ notebaseId: z.uuid(),
59
+ cardId: z.uuid(),
60
+ rating: reviewRatingSchema,
61
+ state: cardStateSchema,
62
+ afterScheduleStatus: scheduleStatusSchema,
63
+ reviewedAt: z.coerce.date(),
64
+ durationMs: z.number().int(),
65
+ fsrsReviewLogSnapshot: fsrsReviewLogSnapshotSchema,
66
+ createdAt: z.coerce.date(),
67
+ })
68
+ export type SrsRevlog = z.infer<typeof srsRevlogSchema>
69
+
70
+ export const srsReviewOutputSchema = z.object({
71
+ card: cardSchema,
72
+ revlog: srsRevlogSchema,
73
+ txid: z.number(),
74
+ })
75
+ export type SrsReviewOutput = z.infer<typeof srsReviewOutputSchema>
76
+
77
+ export const srsRollbackReviewOutputSchema = z.object({
78
+ card: cardSchema,
79
+ rolledBackRevlogId: z.uuid(),
80
+ txid: z.number(),
81
+ })
82
+ export type SrsRollbackReviewOutput = z.infer<typeof srsRollbackReviewOutputSchema>
83
+
84
+ function formatLastReviewTime(lastReviewTime: Date | string | null) {
85
+ return lastReviewTime ? new Date(lastReviewTime).toISOString() : nullLastReviewTimeSentinel
86
+ }
87
+
88
+ async function uuidV5(name: string, namespace: string) {
89
+ const namespaceBytes = uuidToBytes(namespace)
90
+ const nameBytes = new TextEncoder().encode(name)
91
+ const input = new Uint8Array(namespaceBytes.length + nameBytes.length)
92
+ input.set(namespaceBytes)
93
+ input.set(nameBytes, namespaceBytes.length)
94
+
95
+ const hash = new Uint8Array(await crypto.subtle.digest("SHA-1", input))
96
+ const bytes = hash.slice(0, 16)
97
+ const versionByte = bytes[6]
98
+ const variantByte = bytes[8]
99
+ if (versionByte === undefined || variantByte === undefined) {
100
+ throw new Error("SHA-1 digest was too short")
101
+ }
102
+ bytes[6] = (versionByte & 0x0F) | 0x50
103
+ bytes[8] = (variantByte & 0x3F) | 0x80
104
+
105
+ return bytesToUuid(bytes)
106
+ }
107
+
108
+ function uuidToBytes(uuid: string) {
109
+ const hex = uuid.replaceAll("-", "").toLowerCase()
110
+ if (!/^[0-9a-f]{32}$/.test(hex)) {
111
+ throw new Error("Invalid UUID namespace")
112
+ }
113
+
114
+ return new Uint8Array(
115
+ Array.from({ length: 16 }, (_, index) =>
116
+ Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16)),
117
+ )
118
+ }
119
+
120
+ function bytesToUuid(bytes: Uint8Array) {
121
+ const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, "0"))
122
+ return [
123
+ hex.slice(0, 4).join(""),
124
+ hex.slice(4, 6).join(""),
125
+ hex.slice(6, 8).join(""),
126
+ hex.slice(8, 10).join(""),
127
+ hex.slice(10, 16).join(""),
128
+ ].join("-")
129
+ }
@@ -0,0 +1,23 @@
1
+ import { z } from "zod"
2
+
3
+ // @ref https://zenn.dev/herp_inc/articles/js-intl-date-time-format-performance
4
+ const localeTimeZoneFormatter = new Map<string, Intl.DateTimeFormat>()
5
+ function createTimezoneFormatter(timezone: string): Intl.DateTimeFormat {
6
+ let formatter = localeTimeZoneFormatter.get(timezone)
7
+ if (!formatter) {
8
+ formatter = new Intl.DateTimeFormat("en-US", { timeZone: timezone })
9
+ localeTimeZoneFormatter.set(timezone, formatter)
10
+ }
11
+ return formatter
12
+ }
13
+
14
+ export const timezoneSchema = z.string().trim().min(1).refine((timezone) => {
15
+ try {
16
+ createTimezoneFormatter(timezone).format(new Date())
17
+ return true
18
+ }
19
+ catch {
20
+ return false
21
+ }
22
+ }, "Invalid timezone")
23
+ export type Timezone = z.infer<typeof timezoneSchema>
@@ -0,0 +1,13 @@
1
+ import { z } from "zod"
2
+ import { timezoneSchema } from "./timezone"
3
+
4
+ export const userEnsureTimezoneInputSchema = z.object({
5
+ timezone: timezoneSchema,
6
+ }).strict()
7
+ export type UserEnsureTimezoneInput = z.infer<typeof userEnsureTimezoneInputSchema>
8
+
9
+ export const userEnsureTimezoneOutputSchema = z.object({
10
+ timezone: timezoneSchema,
11
+ updated: z.boolean(),
12
+ }).strict()
13
+ export type UserEnsureTimezoneOutput = z.infer<typeof userEnsureTimezoneOutputSchema>
@@ -1,62 +0,0 @@
1
- import { pickPublicErrorMap } from "@/public-errors"
2
- import {
3
- ColumnCreateInputSchema,
4
- ColumnCreateOutputSchema,
5
- ColumnDeleteInputSchema,
6
- ColumnDeleteOutputSchema,
7
- ColumnReorderInputSchema,
8
- ColumnReorderOutputSchema,
9
- ColumnUpdateInputSchema,
10
- ColumnUpdateOutputSchema,
11
- } from "@/schemas/column"
12
- import { notebaseProcedure } from "./shared"
13
-
14
- export const columnContract = {
15
- create: notebaseProcedure
16
- .errors(pickPublicErrorMap("TABLE_NOT_FOUND", "CONCURRENT_POSITION_CONFLICT"))
17
- .route({
18
- method: "POST",
19
- path: "/columns",
20
- summary: "Create column",
21
- tags: ["Columns"],
22
- })
23
- .input(ColumnCreateInputSchema)
24
- .output(ColumnCreateOutputSchema),
25
-
26
- update: notebaseProcedure
27
- .errors(pickPublicErrorMap("COLUMN_NOT_FOUND"))
28
- .route({
29
- method: "PATCH",
30
- path: "/columns/{columnId}",
31
- summary: "Update column",
32
- tags: ["Columns"],
33
- })
34
- .input(ColumnUpdateInputSchema)
35
- .output(ColumnUpdateOutputSchema),
36
-
37
- delete: notebaseProcedure
38
- .errors(pickPublicErrorMap(
39
- "COLUMN_NOT_FOUND",
40
- "PRIMARY_COLUMN_DELETE_NOT_ALLOWED",
41
- "CONCURRENT_POSITION_CONFLICT",
42
- ))
43
- .route({
44
- method: "DELETE",
45
- path: "/columns/{columnId}",
46
- summary: "Delete column",
47
- tags: ["Columns"],
48
- })
49
- .input(ColumnDeleteInputSchema)
50
- .output(ColumnDeleteOutputSchema),
51
-
52
- reorder: notebaseProcedure
53
- .errors(pickPublicErrorMap("TABLE_NOT_FOUND", "CONCURRENT_POSITION_CONFLICT"))
54
- .route({
55
- method: "POST",
56
- path: "/columns/reorder",
57
- summary: "Reorder columns in a table",
58
- tags: ["Columns"],
59
- })
60
- .input(ColumnReorderInputSchema)
61
- .output(ColumnReorderOutputSchema),
62
- }
@@ -1,82 +0,0 @@
1
- import { pickPublicErrorMap } from "@/public-errors"
2
- import {
3
- CustomTableCreateInputSchema,
4
- CustomTableCreateOutputSchema,
5
- CustomTableDeleteInputSchema,
6
- CustomTableDeleteOutputSchema,
7
- CustomTableGetInputSchema,
8
- CustomTableGetOutputSchema,
9
- CustomTableGetSchemaInputSchema,
10
- CustomTableGetSchemaOutputSchema,
11
- CustomTableListInputSchema,
12
- CustomTableListOutputSchema,
13
- CustomTableUpdateInputSchema,
14
- CustomTableUpdateOutputSchema,
15
- } from "@/schemas/custom-table"
16
- import { notebaseProcedure } from "./shared"
17
-
18
- export const customTableContract = {
19
- list: notebaseProcedure
20
- .route({
21
- method: "GET",
22
- path: "/custom-tables",
23
- summary: "List custom tables",
24
- tags: ["Custom Tables"],
25
- })
26
- .input(CustomTableListInputSchema)
27
- .output(CustomTableListOutputSchema),
28
-
29
- get: notebaseProcedure
30
- .errors(pickPublicErrorMap("TABLE_NOT_FOUND"))
31
- .route({
32
- method: "GET",
33
- path: "/custom-tables/{id}",
34
- summary: "Get custom table with columns, rows, and views",
35
- tags: ["Custom Tables"],
36
- })
37
- .input(CustomTableGetInputSchema)
38
- .output(CustomTableGetOutputSchema),
39
-
40
- getSchema: notebaseProcedure
41
- .errors(pickPublicErrorMap("TABLE_NOT_FOUND"))
42
- .route({
43
- method: "GET",
44
- path: "/custom-tables/{id}/schema",
45
- summary: "Get custom table schema",
46
- tags: ["Custom Tables"],
47
- })
48
- .input(CustomTableGetSchemaInputSchema)
49
- .output(CustomTableGetSchemaOutputSchema),
50
-
51
- create: notebaseProcedure
52
- .route({
53
- method: "POST",
54
- path: "/custom-tables",
55
- summary: "Create custom table",
56
- tags: ["Custom Tables"],
57
- })
58
- .input(CustomTableCreateInputSchema)
59
- .output(CustomTableCreateOutputSchema),
60
-
61
- update: notebaseProcedure
62
- .errors(pickPublicErrorMap("TABLE_NOT_FOUND"))
63
- .route({
64
- method: "PUT",
65
- path: "/custom-tables/{id}",
66
- summary: "Update custom table",
67
- tags: ["Custom Tables"],
68
- })
69
- .input(CustomTableUpdateInputSchema)
70
- .output(CustomTableUpdateOutputSchema),
71
-
72
- delete: notebaseProcedure
73
- .errors(pickPublicErrorMap("TABLE_NOT_FOUND"))
74
- .route({
75
- method: "DELETE",
76
- path: "/custom-tables/{id}",
77
- summary: "Delete custom table",
78
- tags: ["Custom Tables"],
79
- })
80
- .input(CustomTableDeleteInputSchema)
81
- .output(CustomTableDeleteOutputSchema),
82
- }
@@ -1,62 +0,0 @@
1
- import { pickPublicErrorMap } from "@/public-errors"
2
- import {
3
- RowCreateInputSchema,
4
- RowCreateOutputSchema,
5
- RowDeleteInputSchema,
6
- RowDeleteOutputSchema,
7
- RowReorderInputSchema,
8
- RowReorderOutputSchema,
9
- RowUpdateInputSchema,
10
- RowUpdateOutputSchema,
11
- } from "@/schemas/row"
12
- import { notebaseProcedure } from "./shared"
13
-
14
- export const rowContract = {
15
- create: notebaseProcedure
16
- .errors(pickPublicErrorMap(
17
- "TABLE_NOT_FOUND",
18
- "CELL_VALIDATION_FAILED",
19
- "CONCURRENT_POSITION_CONFLICT",
20
- ))
21
- .route({
22
- method: "POST",
23
- path: "/rows",
24
- summary: "Create row",
25
- tags: ["Rows"],
26
- })
27
- .input(RowCreateInputSchema)
28
- .output(RowCreateOutputSchema),
29
-
30
- update: notebaseProcedure
31
- .errors(pickPublicErrorMap("ROW_NOT_FOUND", "CELL_VALIDATION_FAILED"))
32
- .route({
33
- method: "PATCH",
34
- path: "/rows/{rowId}",
35
- summary: "Update row cells",
36
- tags: ["Rows"],
37
- })
38
- .input(RowUpdateInputSchema)
39
- .output(RowUpdateOutputSchema),
40
-
41
- delete: notebaseProcedure
42
- .errors(pickPublicErrorMap("ROW_NOT_FOUND", "CONCURRENT_POSITION_CONFLICT"))
43
- .route({
44
- method: "DELETE",
45
- path: "/rows/{rowId}",
46
- summary: "Delete row",
47
- tags: ["Rows"],
48
- })
49
- .input(RowDeleteInputSchema)
50
- .output(RowDeleteOutputSchema),
51
-
52
- reorder: notebaseProcedure
53
- .errors(pickPublicErrorMap("TABLE_NOT_FOUND", "CONCURRENT_POSITION_CONFLICT"))
54
- .route({
55
- method: "POST",
56
- path: "/rows/reorder",
57
- summary: "Reorder rows in a table",
58
- tags: ["Rows"],
59
- })
60
- .input(RowReorderInputSchema)
61
- .output(RowReorderOutputSchema),
62
- }
@@ -1,74 +0,0 @@
1
- import { COLUMN_MAX_WIDTH, COLUMN_MIN_WIDTH, columnConfigSchema } from "@read-frog/definitions"
2
- import { z } from "zod"
3
-
4
- export const columnWidthSchema = z.number().int().min(COLUMN_MIN_WIDTH).max(COLUMN_MAX_WIDTH)
5
-
6
- export const tableColumnSchema = z.object({
7
- id: z.string(),
8
- tableId: z.string(),
9
- name: z.string(),
10
- config: columnConfigSchema,
11
- position: z.number(),
12
- isPrimary: z.boolean(),
13
- width: z.number().nullable(),
14
- createdAt: z.coerce.date(),
15
- updatedAt: z.coerce.date(),
16
- })
17
- export type TableColumn = z.infer<typeof tableColumnSchema>
18
-
19
- export const columnCreateDataSchema = z.object({
20
- id: z.uuid().optional(),
21
- name: z.string().min(1),
22
- config: columnConfigSchema,
23
- }).strict()
24
- export type ColumnCreateData = z.infer<typeof columnCreateDataSchema>
25
-
26
- export const columnUpdateDataSchema = z.object({
27
- name: z.string().min(1).optional(),
28
- config: columnConfigSchema.optional(),
29
- width: columnWidthSchema.nullable().optional(),
30
- }).strict()
31
- export type ColumnUpdateData = z.infer<typeof columnUpdateDataSchema>
32
-
33
- export const ColumnCreateInputSchema = z.object({
34
- tableId: z.uuid(),
35
- data: columnCreateDataSchema,
36
- })
37
- export type ColumnCreateInput = z.infer<typeof ColumnCreateInputSchema>
38
-
39
- export const ColumnCreateOutputSchema = z.object({
40
- txid: z.number(),
41
- })
42
- export type ColumnCreateOutput = z.infer<typeof ColumnCreateOutputSchema>
43
-
44
- export const ColumnUpdateInputSchema = z.object({
45
- columnId: z.uuid(),
46
- data: columnUpdateDataSchema,
47
- })
48
- export type ColumnUpdateInput = z.infer<typeof ColumnUpdateInputSchema>
49
-
50
- export const ColumnUpdateOutputSchema = z.object({
51
- txid: z.number(),
52
- })
53
- export type ColumnUpdateOutput = z.infer<typeof ColumnUpdateOutputSchema>
54
-
55
- export const ColumnDeleteInputSchema = z.object({
56
- columnId: z.uuid(),
57
- })
58
- export type ColumnDeleteInput = z.infer<typeof ColumnDeleteInputSchema>
59
-
60
- export const ColumnDeleteOutputSchema = z.object({
61
- txid: z.number(),
62
- })
63
- export type ColumnDeleteOutput = z.infer<typeof ColumnDeleteOutputSchema>
64
-
65
- export const ColumnReorderInputSchema = z.object({
66
- tableId: z.uuid(),
67
- ids: z.array(z.uuid()),
68
- })
69
- export type ColumnReorderInput = z.infer<typeof ColumnReorderInputSchema>
70
-
71
- export const ColumnReorderOutputSchema = z.object({
72
- txid: z.number(),
73
- })
74
- export type ColumnReorderOutput = z.infer<typeof ColumnReorderOutputSchema>
@@ -1,86 +0,0 @@
1
- import { z } from "zod"
2
- import { tableColumnSchema } from "./column"
3
- import { tableRowSchema } from "./row"
4
- import { tableViewSchema } from "./view"
5
-
6
- export const CustomTableListInputSchema = z.object({})
7
- export type CustomTableListInput = z.infer<typeof CustomTableListInputSchema>
8
-
9
- export const CustomTableListItemSchema = z.object({
10
- id: z.string(),
11
- name: z.string(),
12
- })
13
- export type CustomTableListItem = z.infer<typeof CustomTableListItemSchema>
14
-
15
- export const CustomTableListOutputSchema = z.array(CustomTableListItemSchema)
16
- export type CustomTableListOutput = z.infer<typeof CustomTableListOutputSchema>
17
-
18
- export const customTableCreateDataSchema = z.object({
19
- id: z.uuid().optional(),
20
- name: z.string().min(1),
21
- }).strict()
22
- export type CustomTableCreateData = z.infer<typeof customTableCreateDataSchema>
23
-
24
- export const CustomTableCreateInputSchema = customTableCreateDataSchema
25
- export type CustomTableCreateInput = z.infer<typeof CustomTableCreateInputSchema>
26
-
27
- export const CustomTableCreateOutputSchema = z.object({
28
- txid: z.number(),
29
- })
30
- export type CustomTableCreateOutput = z.infer<typeof CustomTableCreateOutputSchema>
31
-
32
- export const customTableUpdateDataSchema = z.object({
33
- name: z.string().min(1).optional(),
34
- }).strict()
35
- export type CustomTableUpdateData = z.infer<typeof customTableUpdateDataSchema>
36
-
37
- export const CustomTableUpdateInputSchema = customTableUpdateDataSchema.extend({
38
- id: z.uuid(),
39
- })
40
- export type CustomTableUpdateInput = z.infer<typeof CustomTableUpdateInputSchema>
41
-
42
- export const CustomTableUpdateOutputSchema = z.object({
43
- txid: z.number(),
44
- })
45
- export type CustomTableUpdateOutput = z.infer<typeof CustomTableUpdateOutputSchema>
46
-
47
- export const CustomTableDeleteInputSchema = z.object({
48
- id: z.uuid(),
49
- })
50
- export type CustomTableDeleteInput = z.infer<typeof CustomTableDeleteInputSchema>
51
-
52
- export const CustomTableDeleteOutputSchema = z.object({
53
- txid: z.number(),
54
- })
55
- export type CustomTableDeleteOutput = z.infer<typeof CustomTableDeleteOutputSchema>
56
-
57
- // Get endpoint schemas
58
- export const CustomTableGetInputSchema = z.object({
59
- id: z.uuid(),
60
- })
61
- export type CustomTableGetInput = z.infer<typeof CustomTableGetInputSchema>
62
-
63
- export const CustomTableGetSchemaInputSchema = z.object({
64
- id: z.uuid(),
65
- })
66
- export type CustomTableGetSchemaInput = z.infer<typeof CustomTableGetSchemaInputSchema>
67
-
68
- export const CustomTableGetOutputSchema = z.object({
69
- id: z.string(),
70
- userId: z.string(),
71
- name: z.string(),
72
- createdAt: z.coerce.date(),
73
- updatedAt: z.coerce.date(),
74
- columns: z.array(tableColumnSchema),
75
- rows: z.array(tableRowSchema),
76
- views: z.array(tableViewSchema),
77
- })
78
- export type CustomTableGetOutput = z.infer<typeof CustomTableGetOutputSchema>
79
-
80
- export const CustomTableGetSchemaOutputSchema = z.object({
81
- id: z.string(),
82
- name: z.string(),
83
- updatedAt: z.coerce.date(),
84
- columns: z.array(tableColumnSchema),
85
- })
86
- export type CustomTableGetSchemaOutput = z.infer<typeof CustomTableGetSchemaOutputSchema>
@@ -1,73 +0,0 @@
1
- import { z } from "zod"
2
-
3
- export const rowCellsSchema = z.record(z.string(), z.unknown())
4
-
5
- export const tableRowSchema = z.object({
6
- id: z.string(),
7
- tableId: z.string(),
8
- cells: rowCellsSchema,
9
- position: z.number(),
10
- createdAt: z.coerce.date(),
11
- updatedAt: z.coerce.date(),
12
- })
13
- export type TableRow = z.infer<typeof tableRowSchema>
14
-
15
- export const rowCreateDataSchema = z.object({
16
- id: z.uuid().optional(),
17
- cells: rowCellsSchema.optional(),
18
- }).strict()
19
- export type RowCreateData = z.infer<typeof rowCreateDataSchema>
20
-
21
- export const rowUpdateDataSchema = z.object({
22
- cells: rowCellsSchema.optional(),
23
- }).strict()
24
- export type RowUpdateData = z.infer<typeof rowUpdateDataSchema>
25
-
26
- export const RowCreateInputSchema = z.object({
27
- tableId: z.uuid(),
28
- data: rowCreateDataSchema,
29
- })
30
- export type RowCreateInput = z.infer<typeof RowCreateInputSchema>
31
-
32
- export const RowCreateOutputSchema = z.object({
33
- txid: z.number(),
34
- })
35
- export type RowCreateOutput = z.infer<typeof RowCreateOutputSchema>
36
-
37
- export const RowUpdateInputSchema = z.object({
38
- rowId: z.uuid(),
39
- data: rowUpdateDataSchema,
40
- })
41
- export type RowUpdateInput = z.infer<typeof RowUpdateInputSchema>
42
-
43
- export const RowUpdateOutputSchema = z.object({
44
- id: z.uuid(),
45
- tableId: z.uuid(),
46
- cells: rowCellsSchema,
47
- position: z.number().int(),
48
- createdAt: z.date(),
49
- updatedAt: z.date(),
50
- txid: z.number(),
51
- })
52
- export type RowUpdateOutput = z.infer<typeof RowUpdateOutputSchema>
53
-
54
- export const RowDeleteInputSchema = z.object({
55
- rowId: z.uuid(),
56
- })
57
- export type RowDeleteInput = z.infer<typeof RowDeleteInputSchema>
58
-
59
- export const RowDeleteOutputSchema = z.object({
60
- txid: z.number(),
61
- })
62
- export type RowDeleteOutput = z.infer<typeof RowDeleteOutputSchema>
63
-
64
- export const RowReorderInputSchema = z.object({
65
- tableId: z.uuid(),
66
- ids: z.array(z.uuid()),
67
- })
68
- export type RowReorderInput = z.infer<typeof RowReorderInputSchema>
69
-
70
- export const RowReorderOutputSchema = z.object({
71
- txid: z.number(),
72
- })
73
- export type RowReorderOutput = z.infer<typeof RowReorderOutputSchema>
@@ -1,61 +0,0 @@
1
- import { z } from "zod"
2
-
3
- export const tableViewTypeSchema = z.enum(["table", "kanban", "gallery"])
4
- export type TableViewType = z.infer<typeof tableViewTypeSchema>
5
-
6
- export const viewConfigSchema = z.object({
7
- columnWidths: z.record(z.string(), z.number()).optional(),
8
- hiddenColumns: z.array(z.string()).optional(),
9
- groupByColumnId: z.string().optional(),
10
- }).catchall(z.unknown())
11
- export type ViewConfig = z.infer<typeof viewConfigSchema>
12
-
13
- export const viewFilterSchema = z.object({
14
- columnId: z.string(),
15
- operator: z.string(),
16
- value: z.unknown(),
17
- }).strict()
18
- export type ViewFilter = z.infer<typeof viewFilterSchema>
19
-
20
- export const viewFiltersSchema = z.array(viewFilterSchema)
21
-
22
- export const viewSortSchema = z.object({
23
- columnId: z.string(),
24
- direction: z.enum(["asc", "desc"]),
25
- }).strict()
26
- export type ViewSort = z.infer<typeof viewSortSchema>
27
-
28
- export const viewSortsSchema = z.array(viewSortSchema)
29
-
30
- export const viewCreateDataSchema = z.object({
31
- id: z.uuid().optional(),
32
- name: z.string().min(1),
33
- type: tableViewTypeSchema,
34
- config: viewConfigSchema.optional(),
35
- filters: viewFiltersSchema.optional(),
36
- sorts: viewSortsSchema.optional(),
37
- }).strict()
38
- export type ViewCreateData = z.infer<typeof viewCreateDataSchema>
39
-
40
- export const viewUpdateDataSchema = z.object({
41
- name: z.string().min(1).optional(),
42
- type: tableViewTypeSchema.optional(),
43
- config: viewConfigSchema.optional(),
44
- filters: viewFiltersSchema.optional(),
45
- sorts: viewSortsSchema.optional(),
46
- }).strict()
47
- export type ViewUpdateData = z.infer<typeof viewUpdateDataSchema>
48
-
49
- export const tableViewSchema = z.object({
50
- id: z.string(),
51
- tableId: z.string(),
52
- name: z.string(),
53
- type: tableViewTypeSchema,
54
- config: viewConfigSchema.nullable(),
55
- filters: z.array(z.unknown()).nullable(),
56
- sorts: z.array(z.unknown()).nullable(),
57
- position: z.number(),
58
- createdAt: z.coerce.date(),
59
- updatedAt: z.coerce.date(),
60
- })
61
- export type TableView = z.infer<typeof tableViewSchema>