@read-frog/api-contract 0.14.0 → 0.15.0

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.
Files changed (39) hide show
  1. package/dist/index.d.ts +1105 -475
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +264 -97
  4. package/dist/index.js.map +1 -1
  5. package/package.json +15 -14
  6. package/src/contracts/beta-access.ts +3 -6
  7. package/src/contracts/billing.ts +5 -5
  8. package/src/contracts/card-template.ts +45 -39
  9. package/src/contracts/card.ts +22 -19
  10. package/src/contracts/ebook.ts +13 -11
  11. package/src/contracts/hosted-ai.ts +5 -5
  12. package/src/contracts/notebase-column.ts +40 -32
  13. package/src/contracts/notebase-row.ts +85 -45
  14. package/src/contracts/notebase.ts +60 -40
  15. package/src/contracts/shared.ts +21 -2
  16. package/src/contracts/srs.ts +96 -63
  17. package/src/contracts/stats.ts +9 -11
  18. package/src/contracts/user.ts +3 -3
  19. package/src/contracts/video-transcript.ts +22 -12
  20. package/src/index.ts +37 -33
  21. package/src/public-errors.ts +74 -51
  22. package/src/schemas/beta-access.ts +12 -10
  23. package/src/schemas/billing.ts +77 -59
  24. package/src/schemas/card.ts +66 -63
  25. package/src/schemas/ebook.ts +165 -129
  26. package/src/schemas/hosted-ai.ts +84 -74
  27. package/src/schemas/notebase-column.ts +50 -36
  28. package/src/schemas/notebase-row.ts +88 -57
  29. package/src/schemas/notebase-stats.ts +28 -20
  30. package/src/schemas/notebase-view.ts +59 -49
  31. package/src/schemas/notebase.ts +136 -96
  32. package/src/schemas/pagination.ts +9 -0
  33. package/src/schemas/resource-mutation.ts +6 -0
  34. package/src/schemas/srs-stats.ts +30 -22
  35. package/src/schemas/srs.ts +152 -106
  36. package/src/schemas/stats.ts +27 -21
  37. package/src/schemas/timezone.ts +19 -16
  38. package/src/schemas/user.ts +27 -19
  39. package/src/schemas/video-transcript.ts +33 -32
@@ -1,20 +1,28 @@
1
- import { notebaseColumnConfigSchema, schedulingParamsShape, srsWeightsSchema } from "@read-frog/definitions"
2
- import { z } from "zod"
3
- import { notebaseColumnSchema } from "./notebase-column"
4
- import { NOTEBASE_ROW_CREATE_MANY_MAX_ROWS, notebaseRowSchema } from "./notebase-row"
5
- import { notebaseViewSchema } from "./notebase-view"
6
-
7
- export const NotebaseListInputSchema = z.object({})
8
- export type NotebaseListInput = z.infer<typeof NotebaseListInputSchema>
9
-
10
- export const NotebaseListItemSchema = z.object({
1
+ import { deletionResultSchema } from "./resource-mutation";
2
+ import {
3
+ notebaseColumnConfigSchema,
4
+ schedulingParamsShape,
5
+ srsWeightsSchema,
6
+ } from "@read-frog/definitions";
7
+ import { z } from "zod";
8
+ import { notebaseColumnSchema } from "./notebase-column";
9
+ import { NOTEBASE_ROW_CREATE_MANY_MAX_ROWS, notebaseRowSchema } from "./notebase-row";
10
+ import { notebaseViewSchema } from "./notebase-view";
11
+
12
+ export const NotebaseListInputSchema = z.object({});
13
+ export type NotebaseListInput = z.infer<typeof NotebaseListInputSchema>;
14
+
15
+ export const notebaseSummarySchema = z.object({
11
16
  id: z.string(),
12
17
  name: z.string(),
13
- })
14
- export type NotebaseListItem = z.infer<typeof NotebaseListItemSchema>
18
+ });
19
+ export type NotebaseSummary = z.infer<typeof notebaseSummarySchema>;
15
20
 
16
- export const NotebaseListOutputSchema = z.array(NotebaseListItemSchema)
17
- export type NotebaseListOutput = z.infer<typeof NotebaseListOutputSchema>
21
+ export const NotebaseListItemSchema = notebaseSummarySchema;
22
+ export type NotebaseListItem = z.infer<typeof NotebaseListItemSchema>;
23
+
24
+ export const NotebaseListOutputSchema = z.array(NotebaseListItemSchema);
25
+ export type NotebaseListOutput = z.infer<typeof NotebaseListOutputSchema>;
18
26
 
19
27
  export const notebaseSchema = z.object({
20
28
  id: z.string(),
@@ -32,105 +40,137 @@ export const notebaseSchema = z.object({
32
40
  srsWeights: srsWeightsSchema.nullable(),
33
41
  createdAt: z.date(),
34
42
  updatedAt: z.date(),
35
- })
36
- export type Notebase = z.infer<typeof notebaseSchema>
37
-
38
- const notebaseInitialRowSchema = z.object({
39
- id: z.uuid().optional(),
40
- cells: z.record(z.string(), z.unknown()),
41
- }).strict()
42
-
43
- export const notebaseCreateDataSchema = z.object({
44
- id: z.uuid().optional(),
45
- name: z.string().min(1),
46
- options: z.object({
47
- initialColumns: z.array(z.object({
48
- id: z.uuid(),
49
- name: z.string().min(1),
50
- config: notebaseColumnConfigSchema,
51
- }).strict()).min(1),
52
- initialRow: notebaseInitialRowSchema.optional(),
53
- initialRows: z.array(notebaseInitialRowSchema).min(1).max(NOTEBASE_ROW_CREATE_MANY_MAX_ROWS).optional(),
54
- }).strict().superRefine((options, ctx) => {
55
- if (options.initialRow && options.initialRows) {
56
- ctx.addIssue({
57
- code: "custom",
58
- message: "Provide either initialRow or initialRows, not both.",
59
- path: ["initialRows"],
43
+ });
44
+ export type Notebase = z.infer<typeof notebaseSchema>;
45
+
46
+ const notebaseInitialRowSchema = z
47
+ .object({
48
+ id: z.uuid().optional(),
49
+ cells: z.record(z.string(), z.unknown()),
50
+ })
51
+ .strict();
52
+
53
+ export const notebaseCreateDataSchema = z
54
+ .object({
55
+ id: z.uuid().optional(),
56
+ name: z.string().min(1),
57
+ options: z
58
+ .object({
59
+ initialColumns: z
60
+ .array(
61
+ z
62
+ .object({
63
+ id: z.uuid(),
64
+ name: z.string().min(1),
65
+ config: notebaseColumnConfigSchema,
66
+ })
67
+ .strict(),
68
+ )
69
+ .min(1),
70
+ initialRow: notebaseInitialRowSchema.optional(),
71
+ initialRows: z
72
+ .array(notebaseInitialRowSchema)
73
+ .min(1)
74
+ .max(NOTEBASE_ROW_CREATE_MANY_MAX_ROWS)
75
+ .optional(),
76
+ })
77
+ .strict()
78
+ .superRefine((options, ctx) => {
79
+ if (options.initialRow && options.initialRows) {
80
+ ctx.addIssue({
81
+ code: "custom",
82
+ message: "Provide either initialRow or initialRows, not both.",
83
+ path: ["initialRows"],
84
+ });
85
+ }
86
+
87
+ if (!options.initialRows) {
88
+ return;
89
+ }
90
+
91
+ const seenIds = new Set<string>();
92
+ options.initialRows.forEach((row, index) => {
93
+ if (row.id === undefined) {
94
+ return;
95
+ }
96
+
97
+ if (seenIds.has(row.id)) {
98
+ ctx.addIssue({
99
+ code: "custom",
100
+ message: `Duplicate row id "${row.id}".`,
101
+ path: ["initialRows", index, "id"],
102
+ });
103
+ return;
104
+ }
105
+
106
+ seenIds.add(row.id);
107
+ });
60
108
  })
61
- }
62
-
63
- if (!options.initialRows) {
64
- return
65
- }
66
-
67
- const seenIds = new Set<string>()
68
- options.initialRows.forEach((row, index) => {
69
- if (row.id === undefined) {
70
- return
71
- }
72
-
73
- if (seenIds.has(row.id)) {
74
- ctx.addIssue({
75
- code: "custom",
76
- message: `Duplicate row id "${row.id}".`,
77
- path: ["initialRows", index, "id"],
78
- })
79
- return
80
- }
81
-
82
- seenIds.add(row.id)
83
- })
84
- }).optional(),
85
- }).strict()
86
- export type NotebaseCreateData = z.infer<typeof notebaseCreateDataSchema>
87
-
88
- export const NotebaseCreateInputSchema = notebaseCreateDataSchema
89
- export type NotebaseCreateInput = z.infer<typeof NotebaseCreateInputSchema>
109
+ .optional(),
110
+ })
111
+ .strict();
112
+ export type NotebaseCreateData = z.infer<typeof notebaseCreateDataSchema>;
113
+
114
+ export const NotebaseCreateInputSchema = notebaseCreateDataSchema;
115
+ export type NotebaseCreateInput = z.infer<typeof NotebaseCreateInputSchema>;
90
116
 
91
117
  export const NotebaseCreateOutputSchema = z.object({
118
+ notebase: notebaseSchema,
92
119
  txid: z.number(),
93
- })
94
- export type NotebaseCreateOutput = z.infer<typeof NotebaseCreateOutputSchema>
95
-
96
- export const notebaseUpdateDataSchema = z.object({
97
- name: z.string().min(1).optional(),
98
- srsNewPerDay: schedulingParamsShape.newPerDay.optional(),
99
- srsReviewsPerDay: schedulingParamsShape.reviewsPerDay.optional(),
100
- srsDesiredRetention: schedulingParamsShape.desiredRetention.optional(),
101
- }).strict()
102
- export type NotebaseUpdateData = z.infer<typeof notebaseUpdateDataSchema>
120
+ });
121
+ export type NotebaseCreateOutput = z.infer<typeof NotebaseCreateOutputSchema>;
122
+
123
+ export const notebaseUpdateDataSchema = z
124
+ .object({
125
+ name: z.string().min(1).optional(),
126
+ srsNewPerDay: schedulingParamsShape.newPerDay.optional(),
127
+ srsReviewsPerDay: schedulingParamsShape.reviewsPerDay.optional(),
128
+ srsDesiredRetention: schedulingParamsShape.desiredRetention.optional(),
129
+ })
130
+ .strict();
131
+ export type NotebaseUpdateData = z.infer<typeof notebaseUpdateDataSchema>;
103
132
 
104
133
  export const NotebaseUpdateInputSchema = notebaseUpdateDataSchema.extend({
105
134
  id: z.uuid(),
106
- })
107
- export type NotebaseUpdateInput = z.infer<typeof NotebaseUpdateInputSchema>
135
+ });
136
+ export type NotebaseUpdateInput = z.infer<typeof NotebaseUpdateInputSchema>;
108
137
 
109
138
  export const NotebaseUpdateOutputSchema = z.object({
139
+ notebase: notebaseSchema,
110
140
  txid: z.number(),
111
- })
112
- export type NotebaseUpdateOutput = z.infer<typeof NotebaseUpdateOutputSchema>
141
+ });
142
+ export type NotebaseUpdateOutput = z.infer<typeof NotebaseUpdateOutputSchema>;
113
143
 
114
144
  export const NotebaseDeleteInputSchema = z.object({
115
145
  id: z.uuid(),
116
- })
117
- export type NotebaseDeleteInput = z.infer<typeof NotebaseDeleteInputSchema>
146
+ });
147
+ export type NotebaseDeleteInput = z.infer<typeof NotebaseDeleteInputSchema>;
118
148
 
119
- export const NotebaseDeleteOutputSchema = z.object({
120
- txid: z.number(),
121
- })
122
- export type NotebaseDeleteOutput = z.infer<typeof NotebaseDeleteOutputSchema>
149
+ export const NotebaseDeleteOutputSchema = deletionResultSchema;
150
+ export type NotebaseDeleteOutput = z.infer<typeof NotebaseDeleteOutputSchema>;
123
151
 
124
152
  // Get endpoint schemas
125
153
  export const NotebaseGetInputSchema = z.object({
126
154
  id: z.uuid(),
127
- })
128
- export type NotebaseGetInput = z.infer<typeof NotebaseGetInputSchema>
155
+ });
156
+ export type NotebaseGetInput = z.infer<typeof NotebaseGetInputSchema>;
157
+
158
+ export const NotebaseGetSummaryInputSchema = z.object({
159
+ id: z.uuid(),
160
+ });
161
+ export type NotebaseGetSummaryInput = z.infer<typeof NotebaseGetSummaryInputSchema>;
162
+
163
+ export const NotebaseGetSummaryOutputSchema = notebaseSummarySchema.extend({
164
+ srsNewPerDay: schedulingParamsShape.newPerDay,
165
+ srsReviewsPerDay: schedulingParamsShape.reviewsPerDay,
166
+ srsDesiredRetention: schedulingParamsShape.desiredRetention,
167
+ });
168
+ export type NotebaseGetSummaryOutput = z.infer<typeof NotebaseGetSummaryOutputSchema>;
129
169
 
130
170
  export const NotebaseGetSchemaInputSchema = z.object({
131
171
  id: z.uuid(),
132
- })
133
- export type NotebaseGetSchemaInput = z.infer<typeof NotebaseGetSchemaInputSchema>
172
+ });
173
+ export type NotebaseGetSchemaInput = z.infer<typeof NotebaseGetSchemaInputSchema>;
134
174
 
135
175
  export const NotebaseGetOutputSchema = notebaseSchema.extend({
136
176
  createdAt: z.coerce.date(),
@@ -138,13 +178,13 @@ export const NotebaseGetOutputSchema = notebaseSchema.extend({
138
178
  notebaseColumns: z.array(notebaseColumnSchema),
139
179
  notebaseRows: z.array(notebaseRowSchema),
140
180
  notebaseViews: z.array(notebaseViewSchema),
141
- })
142
- export type NotebaseGetOutput = z.infer<typeof NotebaseGetOutputSchema>
181
+ });
182
+ export type NotebaseGetOutput = z.infer<typeof NotebaseGetOutputSchema>;
143
183
 
144
184
  export const NotebaseGetSchemaOutputSchema = z.object({
145
185
  id: z.string(),
146
186
  name: z.string(),
147
187
  updatedAt: z.coerce.date(),
148
188
  notebaseColumns: z.array(notebaseColumnSchema),
149
- })
150
- export type NotebaseGetSchemaOutput = z.infer<typeof NotebaseGetSchemaOutputSchema>
189
+ });
190
+ export type NotebaseGetSchemaOutput = z.infer<typeof NotebaseGetSchemaOutputSchema>;
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+ export const paginationShape = {
3
+ // Existing callers omit pagination to read all matching records.
4
+ limit: z.number().int().min(1).max(500).optional(),
5
+ offset: z.number().int().min(0).optional(),
6
+ };
7
+ export function pageSchema<T extends z.ZodType>(itemSchema: T) {
8
+ return z.object({ items: z.array(itemSchema), hasMore: z.boolean() });
9
+ }
@@ -0,0 +1,6 @@
1
+ import { z } from "zod";
2
+ export const expectedUpdatedAtSchema = z.iso.datetime({ offset: true });
3
+ export const deletionResultSchema = z.object({
4
+ id: z.uuid(),
5
+ txid: z.number(),
6
+ });
@@ -1,26 +1,34 @@
1
- import { z } from "zod"
1
+ import { z } from "zod";
2
2
 
3
- export const srsActivityStatsItemSchema = z.object({
4
- date: z.iso.date(),
5
- answers: z.number().int().nonnegative(),
6
- durationMs: z.number().int().nonnegative(),
7
- }).strict()
8
- export type SrsActivityStatsItem = z.infer<typeof srsActivityStatsItemSchema>
3
+ export const srsActivityStatsItemSchema = z
4
+ .object({
5
+ date: z.iso.date(),
6
+ answers: z.number().int().nonnegative(),
7
+ durationMs: z.number().int().nonnegative(),
8
+ })
9
+ .strict();
10
+ export type SrsActivityStatsItem = z.infer<typeof srsActivityStatsItemSchema>;
9
11
 
10
- export const srsActivityStatsOutputSchema = z.object({
11
- learnedCards: z.number().int().nonnegative(),
12
- daily: z.array(srsActivityStatsItemSchema),
13
- }).strict()
14
- export type SrsActivityStatsOutput = z.infer<typeof srsActivityStatsOutputSchema>
12
+ export const srsActivityStatsOutputSchema = z
13
+ .object({
14
+ learnedCards: z.number().int().nonnegative(),
15
+ daily: z.array(srsActivityStatsItemSchema),
16
+ })
17
+ .strict();
18
+ export type SrsActivityStatsOutput = z.infer<typeof srsActivityStatsOutputSchema>;
15
19
 
16
- export const srsMemoryGrowthStatsItemSchema = z.object({
17
- date: z.iso.date(),
18
- delta: z.number().int(),
19
- }).strict()
20
- export type SrsMemoryGrowthStatsItem = z.infer<typeof srsMemoryGrowthStatsItemSchema>
20
+ export const srsMemoryGrowthStatsItemSchema = z
21
+ .object({
22
+ date: z.iso.date(),
23
+ delta: z.number().int(),
24
+ })
25
+ .strict();
26
+ export type SrsMemoryGrowthStatsItem = z.infer<typeof srsMemoryGrowthStatsItemSchema>;
21
27
 
22
- export const srsMemoryGrowthStatsOutputSchema = z.object({
23
- baseTotal: z.number().int().nonnegative(),
24
- daily: z.array(srsMemoryGrowthStatsItemSchema),
25
- }).strict()
26
- export type SrsMemoryGrowthStatsOutput = z.infer<typeof srsMemoryGrowthStatsOutputSchema>
28
+ export const srsMemoryGrowthStatsOutputSchema = z
29
+ .object({
30
+ baseTotal: z.number().int().nonnegative(),
31
+ daily: z.array(srsMemoryGrowthStatsItemSchema),
32
+ })
33
+ .strict();
34
+ export type SrsMemoryGrowthStatsOutput = z.infer<typeof srsMemoryGrowthStatsOutputSchema>;