@read-frog/api-contract 0.3.0 → 0.4.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.
- package/dist/index.d.ts +396 -238
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +166 -100
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
- package/src/contracts/beta-access.ts +17 -0
- package/src/contracts/column.ts +62 -0
- package/src/contracts/custom-table.ts +82 -0
- package/src/contracts/row.ts +62 -0
- package/src/contracts/shared.ts +6 -0
- package/src/index.ts +21 -0
- package/src/public-errors.ts +104 -0
- package/src/schemas/beta-access.ts +16 -0
- package/src/schemas/column.ts +74 -0
- package/src/schemas/custom-table.ts +86 -0
- package/src/schemas/row.ts +73 -0
- package/src/schemas/view.ts +61 -0
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ContractRouterClient } from "@orpc/contract"
|
|
2
|
+
import { betaAccessContract } from "./contracts/beta-access"
|
|
3
|
+
import { columnContract } from "./contracts/column"
|
|
4
|
+
import { customTableContract } from "./contracts/custom-table"
|
|
5
|
+
import { rowContract } from "./contracts/row"
|
|
6
|
+
|
|
7
|
+
export const contract = {
|
|
8
|
+
betaAccess: betaAccessContract,
|
|
9
|
+
customTable: customTableContract,
|
|
10
|
+
column: columnContract,
|
|
11
|
+
row: rowContract,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ORPCRouterClient = ContractRouterClient<typeof contract>
|
|
15
|
+
|
|
16
|
+
export * from "./public-errors"
|
|
17
|
+
export * from "./schemas/beta-access"
|
|
18
|
+
export * from "./schemas/column"
|
|
19
|
+
export * from "./schemas/custom-table"
|
|
20
|
+
export * from "./schemas/row"
|
|
21
|
+
export * from "./schemas/view"
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { ErrorMap } from "@orpc/contract"
|
|
2
|
+
import { z } from "zod"
|
|
3
|
+
|
|
4
|
+
interface PublicAppErrorDefinition {
|
|
5
|
+
data?: z.ZodTypeAny
|
|
6
|
+
message: string
|
|
7
|
+
status: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const CellValidationFailureReasonSchema = z.enum([
|
|
11
|
+
"unknown_column",
|
|
12
|
+
"type_mismatch",
|
|
13
|
+
"invalid_select_option",
|
|
14
|
+
"invalid_date_format",
|
|
15
|
+
])
|
|
16
|
+
export type CellValidationFailureReason = z.infer<typeof CellValidationFailureReasonSchema>
|
|
17
|
+
|
|
18
|
+
export const CellValidationFailureDetailsSchema = z.object({
|
|
19
|
+
expectedFormat: z.string().optional(),
|
|
20
|
+
expectedType: z.string().optional(),
|
|
21
|
+
receivedType: z.string().optional(),
|
|
22
|
+
receivedValue: z.unknown().optional(),
|
|
23
|
+
validOptions: z.array(z.string()).optional(),
|
|
24
|
+
}).strict()
|
|
25
|
+
export type CellValidationFailureDetails = z.infer<typeof CellValidationFailureDetailsSchema>
|
|
26
|
+
|
|
27
|
+
export const CellValidationFailedDataSchema = z.object({
|
|
28
|
+
columnId: z.string(),
|
|
29
|
+
details: CellValidationFailureDetailsSchema,
|
|
30
|
+
reason: CellValidationFailureReasonSchema,
|
|
31
|
+
}).strict()
|
|
32
|
+
export type CellValidationFailedData = z.infer<typeof CellValidationFailedDataSchema>
|
|
33
|
+
|
|
34
|
+
export const PUBLIC_APP_ERROR_DEFS = {
|
|
35
|
+
NOTEBASE_BETA_RESTRICTED: {
|
|
36
|
+
message: "Notebase is currently in beta for selected accounts",
|
|
37
|
+
status: 403,
|
|
38
|
+
},
|
|
39
|
+
TABLE_NOT_FOUND: {
|
|
40
|
+
message: "Table not found",
|
|
41
|
+
status: 404,
|
|
42
|
+
},
|
|
43
|
+
COLUMN_NOT_FOUND: {
|
|
44
|
+
message: "Column not found",
|
|
45
|
+
status: 404,
|
|
46
|
+
},
|
|
47
|
+
ROW_NOT_FOUND: {
|
|
48
|
+
message: "Row not found",
|
|
49
|
+
status: 404,
|
|
50
|
+
},
|
|
51
|
+
VIEW_NOT_FOUND: {
|
|
52
|
+
message: "View not found",
|
|
53
|
+
status: 404,
|
|
54
|
+
},
|
|
55
|
+
CELL_VALIDATION_FAILED: {
|
|
56
|
+
data: CellValidationFailedDataSchema,
|
|
57
|
+
message: "Cell validation failed",
|
|
58
|
+
status: 422,
|
|
59
|
+
},
|
|
60
|
+
PRIMARY_COLUMN_DELETE_NOT_ALLOWED: {
|
|
61
|
+
message: "Cannot delete primary column",
|
|
62
|
+
status: 400,
|
|
63
|
+
},
|
|
64
|
+
CONCURRENT_POSITION_CONFLICT: {
|
|
65
|
+
message: "Concurrent position conflict, please retry",
|
|
66
|
+
status: 409,
|
|
67
|
+
},
|
|
68
|
+
} as const satisfies Record<string, PublicAppErrorDefinition>
|
|
69
|
+
|
|
70
|
+
export type PublicAppErrorCode = keyof typeof PUBLIC_APP_ERROR_DEFS
|
|
71
|
+
|
|
72
|
+
export type PublicAppErrorData<TCode extends PublicAppErrorCode>
|
|
73
|
+
= (typeof PUBLIC_APP_ERROR_DEFS)[TCode] extends { data: infer TSchema extends z.ZodTypeAny }
|
|
74
|
+
? z.output<TSchema>
|
|
75
|
+
: undefined
|
|
76
|
+
|
|
77
|
+
export function isPublicAppErrorCode(code: string | undefined): code is PublicAppErrorCode {
|
|
78
|
+
return code !== undefined && code in PUBLIC_APP_ERROR_DEFS
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function getPublicErrorDefinition<TCode extends PublicAppErrorCode>(code: TCode) {
|
|
82
|
+
return PUBLIC_APP_ERROR_DEFS[code]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function pickPublicErrorMap<const TCodes extends readonly PublicAppErrorCode[]>(
|
|
86
|
+
...codes: TCodes
|
|
87
|
+
) {
|
|
88
|
+
return Object.fromEntries(codes.map((code) => {
|
|
89
|
+
const definition = PUBLIC_APP_ERROR_DEFS[code]
|
|
90
|
+
|
|
91
|
+
if ("data" in definition) {
|
|
92
|
+
return [code, {
|
|
93
|
+
data: definition.data,
|
|
94
|
+
message: definition.message,
|
|
95
|
+
status: definition.status,
|
|
96
|
+
}]
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return [code, {
|
|
100
|
+
message: definition.message,
|
|
101
|
+
status: definition.status,
|
|
102
|
+
}]
|
|
103
|
+
})) as Pick<ErrorMap, TCodes[number]>
|
|
104
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BETA_FEATURE_KEYS } from "@read-frog/definitions"
|
|
2
|
+
import { z } from "zod"
|
|
3
|
+
|
|
4
|
+
export const BetaFeatureKeySchema = z.enum(BETA_FEATURE_KEYS)
|
|
5
|
+
export type BetaFeatureKey = z.infer<typeof BetaFeatureKeySchema>
|
|
6
|
+
|
|
7
|
+
export const BetaAccessStatusInputSchema = z.object({
|
|
8
|
+
featureKey: BetaFeatureKeySchema,
|
|
9
|
+
}).strict()
|
|
10
|
+
export type BetaAccessStatusInput = z.infer<typeof BetaAccessStatusInputSchema>
|
|
11
|
+
|
|
12
|
+
export const BetaAccessStatusOutputSchema = z.object({
|
|
13
|
+
featureKey: BetaFeatureKeySchema,
|
|
14
|
+
allowed: z.boolean(),
|
|
15
|
+
})
|
|
16
|
+
export type BetaAccessStatusOutput = z.infer<typeof BetaAccessStatusOutputSchema>
|
|
@@ -0,0 +1,74 @@
|
|
|
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>
|
|
@@ -0,0 +1,86 @@
|
|
|
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>
|
|
@@ -0,0 +1,73 @@
|
|
|
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>
|
|
@@ -0,0 +1,61 @@
|
|
|
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>
|