@read-frog/api-contract 0.12.6 → 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.
- package/dist/index.d.ts +1171 -480
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +301 -103
- package/dist/index.js.map +1 -1
- package/package.json +15 -14
- package/src/contracts/beta-access.ts +3 -6
- package/src/contracts/billing.ts +5 -5
- package/src/contracts/card-template.ts +45 -39
- package/src/contracts/card.ts +22 -19
- package/src/contracts/ebook.ts +13 -11
- package/src/contracts/hosted-ai.ts +5 -5
- package/src/contracts/notebase-column.ts +40 -32
- package/src/contracts/notebase-row.ts +85 -45
- package/src/contracts/notebase.ts +60 -40
- package/src/contracts/shared.ts +21 -2
- package/src/contracts/srs.ts +96 -63
- package/src/contracts/stats.ts +9 -11
- package/src/contracts/user.ts +3 -3
- package/src/contracts/video-transcript.ts +22 -7
- package/src/index.ts +37 -33
- package/src/public-errors.ts +97 -51
- package/src/schemas/beta-access.ts +12 -10
- package/src/schemas/billing.ts +77 -53
- package/src/schemas/card.ts +66 -63
- package/src/schemas/ebook.ts +165 -129
- package/src/schemas/hosted-ai.ts +84 -74
- package/src/schemas/notebase-column.ts +50 -36
- package/src/schemas/notebase-row.ts +88 -57
- package/src/schemas/notebase-stats.ts +28 -20
- package/src/schemas/notebase-view.ts +59 -49
- package/src/schemas/notebase.ts +136 -96
- package/src/schemas/pagination.ts +9 -0
- package/src/schemas/resource-mutation.ts +6 -0
- package/src/schemas/srs-stats.ts +30 -22
- package/src/schemas/srs.ts +152 -106
- package/src/schemas/stats.ts +27 -21
- package/src/schemas/timezone.ts +19 -16
- package/src/schemas/user.ts +27 -19
- package/src/schemas/video-transcript.ts +53 -24
package/src/public-errors.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { ErrorMap } from "@orpc/contract"
|
|
2
|
-
import { z } from "zod"
|
|
3
|
-
import { HostedAiCreditPolicyIdSchema, HostedAiModelTierSchema } from "./schemas/hosted-ai"
|
|
1
|
+
import type { ErrorMap } from "@orpc/contract";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { HostedAiCreditPolicyIdSchema, HostedAiModelTierSchema } from "./schemas/hosted-ai";
|
|
4
4
|
|
|
5
5
|
interface PublicAppErrorDefinition {
|
|
6
|
-
data?: z.ZodTypeAny
|
|
7
|
-
message: string
|
|
8
|
-
status: number
|
|
6
|
+
data?: z.ZodTypeAny;
|
|
7
|
+
message: string;
|
|
8
|
+
status: number;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export const CellValidationFailureReasonSchema = z.enum([
|
|
@@ -13,35 +13,41 @@ export const CellValidationFailureReasonSchema = z.enum([
|
|
|
13
13
|
"type_mismatch",
|
|
14
14
|
"invalid_select_option",
|
|
15
15
|
"invalid_date_format",
|
|
16
|
-
])
|
|
17
|
-
export type CellValidationFailureReason = z.infer<typeof CellValidationFailureReasonSchema
|
|
16
|
+
]);
|
|
17
|
+
export type CellValidationFailureReason = z.infer<typeof CellValidationFailureReasonSchema>;
|
|
18
18
|
|
|
19
|
-
export const CellValidationFailureDetailsSchema = z
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
export const CellValidationFailureDetailsSchema = z
|
|
20
|
+
.object({
|
|
21
|
+
expectedFormat: z.string().optional(),
|
|
22
|
+
expectedType: z.string().optional(),
|
|
23
|
+
receivedType: z.string().optional(),
|
|
24
|
+
receivedValue: z.unknown().optional(),
|
|
25
|
+
validOptions: z.array(z.string()).optional(),
|
|
26
|
+
})
|
|
27
|
+
.strict();
|
|
28
|
+
export type CellValidationFailureDetails = z.infer<typeof CellValidationFailureDetailsSchema>;
|
|
27
29
|
|
|
28
|
-
export const CellValidationFailedDataSchema = z
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
export const CellValidationFailedDataSchema = z
|
|
31
|
+
.object({
|
|
32
|
+
notebaseColumnId: z.string(),
|
|
33
|
+
details: CellValidationFailureDetailsSchema,
|
|
34
|
+
reason: CellValidationFailureReasonSchema,
|
|
35
|
+
/** Index of the failing row within a batch input (createMany / initialRows). */
|
|
36
|
+
rowIndex: z.number().int().min(0).optional(),
|
|
37
|
+
})
|
|
38
|
+
.strict();
|
|
39
|
+
export type CellValidationFailedData = z.infer<typeof CellValidationFailedDataSchema>;
|
|
36
40
|
|
|
37
|
-
export const CardTemplateInvalidColumnsDataSchema = z
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
export const CardTemplateInvalidColumnsDataSchema = z
|
|
42
|
+
.object({
|
|
43
|
+
notebaseColumnIds: z.array(z.string()),
|
|
44
|
+
})
|
|
45
|
+
.strict();
|
|
46
|
+
export type CardTemplateInvalidColumnsData = z.infer<typeof CardTemplateInvalidColumnsDataSchema>;
|
|
41
47
|
|
|
42
48
|
export const HostedAiTierRestrictedDataSchema = z.strictObject({
|
|
43
49
|
modelTier: HostedAiModelTierSchema,
|
|
44
|
-
})
|
|
50
|
+
});
|
|
45
51
|
|
|
46
52
|
export const HostedAiQuotaExhaustedDataSchema = z.strictObject({
|
|
47
53
|
modelTier: HostedAiModelTierSchema,
|
|
@@ -52,9 +58,18 @@ export const HostedAiQuotaExhaustedDataSchema = z.strictObject({
|
|
|
52
58
|
policyId: HostedAiCreditPolicyIdSchema,
|
|
53
59
|
usedPercent: z.number().min(0).max(100),
|
|
54
60
|
resetAt: z.iso.datetime().nullable(),
|
|
55
|
-
})
|
|
61
|
+
});
|
|
56
62
|
|
|
57
63
|
export const PUBLIC_APP_ERROR_DEFS = {
|
|
64
|
+
RESOURCE_UPDATE_CONFLICT: {
|
|
65
|
+
message: "The resource changed. Read it again before updating.",
|
|
66
|
+
status: 409,
|
|
67
|
+
},
|
|
68
|
+
RESOURCE_ALREADY_EXISTS: { message: "A resource with this ID already exists.", status: 409 },
|
|
69
|
+
FIELD_TYPE_CHANGE_UNSUPPORTED: {
|
|
70
|
+
message: "This operation cannot change the field type.",
|
|
71
|
+
status: 400,
|
|
72
|
+
},
|
|
58
73
|
HOSTED_AI_TIER_RESTRICTED: {
|
|
59
74
|
data: HostedAiTierRestrictedDataSchema,
|
|
60
75
|
message: "This Built-in AI tier is not available for this account",
|
|
@@ -73,10 +88,26 @@ export const PUBLIC_APP_ERROR_DEFS = {
|
|
|
73
88
|
message: "Notebase not found",
|
|
74
89
|
status: 404,
|
|
75
90
|
},
|
|
91
|
+
// Retired at launch (2026-08-14) but kept defined for one release so old
|
|
92
|
+
// clients' error maps keep parsing; the server no longer emits it. Remove
|
|
93
|
+
// together with the beta feature key in the follow-up cleanup.
|
|
76
94
|
VIDEO_TRANSCRIPTION_BETA_RESTRICTED: {
|
|
77
95
|
message: "Video transcription is currently in beta for selected accounts",
|
|
78
96
|
status: 403,
|
|
79
97
|
},
|
|
98
|
+
VIDEO_TRANSCRIPTION_SUBSCRIPTION_REQUIRED: {
|
|
99
|
+
message: "AI subtitles require a Pro or Ultra subscription",
|
|
100
|
+
status: 403,
|
|
101
|
+
},
|
|
102
|
+
// Dunning (`past_due` / `paused`), not cancellation: the account keeps
|
|
103
|
+
// reading subtitles it already paid to generate, but cannot start new work
|
|
104
|
+
// that spends upstream money until the payment method is fixed. Distinct
|
|
105
|
+
// from SUBSCRIPTION_REQUIRED so the client can say "update your card"
|
|
106
|
+
// instead of "subscribe".
|
|
107
|
+
VIDEO_TRANSCRIPTION_PAYMENT_REQUIRED: {
|
|
108
|
+
message: "Update your payment method to generate new AI subtitles",
|
|
109
|
+
status: 402,
|
|
110
|
+
},
|
|
80
111
|
VIDEO_TRANSCRIPT_NOT_FOUND: {
|
|
81
112
|
message: "Video transcript not found",
|
|
82
113
|
status: 404,
|
|
@@ -89,6 +120,13 @@ export const PUBLIC_APP_ERROR_DEFS = {
|
|
|
89
120
|
message: "Monthly transcription quota exceeded",
|
|
90
121
|
status: 429,
|
|
91
122
|
},
|
|
123
|
+
// A property of the video, not of the account: upgrading or waiting for the
|
|
124
|
+
// quota to reset changes nothing. Kept apart from QUOTA_EXCEEDED so the
|
|
125
|
+
// client does not answer it with an upgrade wall.
|
|
126
|
+
VIDEO_TRANSCRIPTION_UNSUPPORTED_LENGTH: {
|
|
127
|
+
message: "This video is longer than AI subtitles support",
|
|
128
|
+
status: 422,
|
|
129
|
+
},
|
|
92
130
|
NOTEBASE_COLUMN_NOT_FOUND: {
|
|
93
131
|
message: "Notebase column not found",
|
|
94
132
|
status: 404,
|
|
@@ -203,40 +241,48 @@ export const PUBLIC_APP_ERROR_DEFS = {
|
|
|
203
241
|
message: "Ebook upload has not been completed",
|
|
204
242
|
status: 409,
|
|
205
243
|
},
|
|
206
|
-
} as const satisfies Record<string, PublicAppErrorDefinition
|
|
244
|
+
} as const satisfies Record<string, PublicAppErrorDefinition>;
|
|
207
245
|
|
|
208
|
-
export type PublicAppErrorCode = keyof typeof PUBLIC_APP_ERROR_DEFS
|
|
246
|
+
export type PublicAppErrorCode = keyof typeof PUBLIC_APP_ERROR_DEFS;
|
|
209
247
|
|
|
210
|
-
export type PublicAppErrorData<TCode extends PublicAppErrorCode>
|
|
211
|
-
|
|
248
|
+
export type PublicAppErrorData<TCode extends PublicAppErrorCode> =
|
|
249
|
+
(typeof PUBLIC_APP_ERROR_DEFS)[TCode] extends { data: infer TSchema extends z.ZodTypeAny }
|
|
212
250
|
? z.output<TSchema>
|
|
213
|
-
: undefined
|
|
251
|
+
: undefined;
|
|
214
252
|
|
|
215
253
|
export function isPublicAppErrorCode(code: string | undefined): code is PublicAppErrorCode {
|
|
216
|
-
return code !== undefined && code in PUBLIC_APP_ERROR_DEFS
|
|
254
|
+
return code !== undefined && code in PUBLIC_APP_ERROR_DEFS;
|
|
217
255
|
}
|
|
218
256
|
|
|
219
257
|
export function getPublicErrorDefinition<TCode extends PublicAppErrorCode>(code: TCode) {
|
|
220
|
-
return PUBLIC_APP_ERROR_DEFS[code]
|
|
258
|
+
return PUBLIC_APP_ERROR_DEFS[code];
|
|
221
259
|
}
|
|
222
260
|
|
|
223
261
|
export function pickPublicErrorMap<const TCodes extends readonly PublicAppErrorCode[]>(
|
|
224
262
|
...codes: TCodes
|
|
225
263
|
) {
|
|
226
|
-
return Object.fromEntries(
|
|
227
|
-
|
|
264
|
+
return Object.fromEntries(
|
|
265
|
+
codes.map((code) => {
|
|
266
|
+
const definition = PUBLIC_APP_ERROR_DEFS[code];
|
|
228
267
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
268
|
+
if ("data" in definition) {
|
|
269
|
+
return [
|
|
270
|
+
code,
|
|
271
|
+
{
|
|
272
|
+
data: definition.data,
|
|
273
|
+
message: definition.message,
|
|
274
|
+
status: definition.status,
|
|
275
|
+
},
|
|
276
|
+
];
|
|
277
|
+
}
|
|
236
278
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
279
|
+
return [
|
|
280
|
+
code,
|
|
281
|
+
{
|
|
282
|
+
message: definition.message,
|
|
283
|
+
status: definition.status,
|
|
284
|
+
},
|
|
285
|
+
];
|
|
286
|
+
}),
|
|
287
|
+
) as Pick<ErrorMap, TCodes[number]>;
|
|
242
288
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { BETA_FEATURE_KEYS } from "@read-frog/definitions"
|
|
2
|
-
import { z } from "zod"
|
|
1
|
+
import { BETA_FEATURE_KEYS } from "@read-frog/definitions";
|
|
2
|
+
import { z } from "zod";
|
|
3
3
|
|
|
4
|
-
export const BetaFeatureKeySchema = z.enum(BETA_FEATURE_KEYS)
|
|
5
|
-
export type BetaFeatureKey = z.infer<typeof BetaFeatureKeySchema
|
|
4
|
+
export const BetaFeatureKeySchema = z.enum(BETA_FEATURE_KEYS);
|
|
5
|
+
export type BetaFeatureKey = z.infer<typeof BetaFeatureKeySchema>;
|
|
6
6
|
|
|
7
|
-
export const BetaAccessStatusInputSchema = z
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export const BetaAccessStatusInputSchema = z
|
|
8
|
+
.object({
|
|
9
|
+
featureKey: BetaFeatureKeySchema,
|
|
10
|
+
})
|
|
11
|
+
.strict();
|
|
12
|
+
export type BetaAccessStatusInput = z.infer<typeof BetaAccessStatusInputSchema>;
|
|
11
13
|
|
|
12
14
|
export const BetaAccessStatusOutputSchema = z.object({
|
|
13
15
|
featureKey: BetaFeatureKeySchema,
|
|
14
16
|
allowed: z.boolean(),
|
|
15
|
-
})
|
|
16
|
-
export type BetaAccessStatusOutput = z.infer<typeof BetaAccessStatusOutputSchema
|
|
17
|
+
});
|
|
18
|
+
export type BetaAccessStatusOutput = z.infer<typeof BetaAccessStatusOutputSchema>;
|
package/src/schemas/billing.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { z } from "zod"
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const billingIntervalSchema = z.enum(["month", "year"])
|
|
4
|
-
export type BillingInterval = z.infer<typeof billingIntervalSchema
|
|
3
|
+
export const billingIntervalSchema = z.enum(["month", "year"]);
|
|
4
|
+
export type BillingInterval = z.infer<typeof billingIntervalSchema>;
|
|
5
5
|
|
|
6
6
|
export const billingSubscriptionStatusSchema = z.enum([
|
|
7
7
|
"incomplete",
|
|
@@ -12,18 +12,18 @@ export const billingSubscriptionStatusSchema = z.enum([
|
|
|
12
12
|
"canceled",
|
|
13
13
|
"unpaid",
|
|
14
14
|
"paused",
|
|
15
|
-
])
|
|
16
|
-
export type BillingSubscriptionStatus = z.infer<typeof billingSubscriptionStatusSchema
|
|
15
|
+
]);
|
|
16
|
+
export type BillingSubscriptionStatus = z.infer<typeof billingSubscriptionStatusSchema>;
|
|
17
17
|
|
|
18
|
-
export const billingPlanSchema = z.enum(["free", "pro", "ultra"])
|
|
19
|
-
export type BillingPlan = z.infer<typeof billingPlanSchema
|
|
18
|
+
export const billingPlanSchema = z.enum(["free", "pro", "ultra"]);
|
|
19
|
+
export type BillingPlan = z.infer<typeof billingPlanSchema>;
|
|
20
20
|
|
|
21
21
|
// Plans a user can actively check out into (the free tier has no price).
|
|
22
|
-
export const billingCheckoutPlanSchema = z.enum(["pro", "ultra"])
|
|
23
|
-
export type BillingCheckoutPlan = z.infer<typeof billingCheckoutPlanSchema
|
|
22
|
+
export const billingCheckoutPlanSchema = z.enum(["pro", "ultra"]);
|
|
23
|
+
export type BillingCheckoutPlan = z.infer<typeof billingCheckoutPlanSchema>;
|
|
24
24
|
|
|
25
|
-
export const billingCurrencySchema = z.enum(["usd", "cad", "cny"])
|
|
26
|
-
export type BillingCurrency = z.infer<typeof billingCurrencySchema
|
|
25
|
+
export const billingCurrencySchema = z.enum(["usd", "cad", "cny"]);
|
|
26
|
+
export type BillingCurrency = z.infer<typeof billingCurrencySchema>;
|
|
27
27
|
|
|
28
28
|
export const billingLocaleSchema = z.enum([
|
|
29
29
|
"en",
|
|
@@ -35,52 +35,76 @@ export const billingLocaleSchema = z.enum([
|
|
|
35
35
|
"vi",
|
|
36
36
|
"zh",
|
|
37
37
|
"zh-TW",
|
|
38
|
-
])
|
|
39
|
-
export type BillingLocale = z.infer<typeof billingLocaleSchema
|
|
38
|
+
]);
|
|
39
|
+
export type BillingLocale = z.infer<typeof billingLocaleSchema>;
|
|
40
40
|
|
|
41
|
-
export const billingAccessSourceSchema = z.enum(["subscription", "pass"])
|
|
42
|
-
export type BillingAccessSource = z.infer<typeof billingAccessSourceSchema
|
|
41
|
+
export const billingAccessSourceSchema = z.enum(["subscription", "pass"]);
|
|
42
|
+
export type BillingAccessSource = z.infer<typeof billingAccessSourceSchema>;
|
|
43
43
|
|
|
44
|
-
export const billingScheduledChangeSchema = z
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
export const billingScheduledChangeSchema = z
|
|
45
|
+
.object({
|
|
46
|
+
plan: billingCheckoutPlanSchema,
|
|
47
|
+
interval: billingIntervalSchema,
|
|
48
|
+
effectiveAt: z.coerce.date(),
|
|
49
|
+
})
|
|
50
|
+
.strict();
|
|
51
|
+
export type BillingScheduledChange = z.infer<typeof billingScheduledChangeSchema>;
|
|
50
52
|
|
|
51
|
-
export const billingStatusSchema = z
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
export const billingStatusSchema = z
|
|
54
|
+
.object({
|
|
55
|
+
plan: billingPlanSchema,
|
|
56
|
+
status: billingSubscriptionStatusSchema.nullable(),
|
|
57
|
+
interval: billingIntervalSchema.nullable(),
|
|
58
|
+
currentPeriodEnd: z.coerce.date().nullable(),
|
|
59
|
+
/**
|
|
60
|
+
* When the subscription terminates, or null if it renews. Replaces the
|
|
61
|
+
* `cancelAtPeriodEnd` boolean: Stripe deprecated its counterpart and the
|
|
62
|
+
* Customer Portal no longer sets it, and the termination date is not always
|
|
63
|
+
* `currentPeriodEnd` — a stacked pass pushes that past the cancellation.
|
|
64
|
+
*/
|
|
65
|
+
cancelAt: z.coerce.date().nullable(),
|
|
66
|
+
accessSource: billingAccessSourceSchema.nullable(),
|
|
67
|
+
scheduledChange: billingScheduledChangeSchema.nullable(),
|
|
68
|
+
unlimitedNotebaseNotes: z.boolean(),
|
|
69
|
+
notebaseNoteLimit: z.number().int().positive(),
|
|
70
|
+
notebaseNoteCount: z.number().int().min(0),
|
|
71
|
+
})
|
|
72
|
+
.strict();
|
|
73
|
+
export type BillingStatus = z.infer<typeof billingStatusSchema>;
|
|
64
74
|
|
|
65
|
-
export const billingCreateCheckoutSessionInputSchema = z
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
export const billingCreateCheckoutSessionInputSchema = z
|
|
76
|
+
.object({
|
|
77
|
+
currency: billingCurrencySchema,
|
|
78
|
+
interval: billingIntervalSchema,
|
|
79
|
+
locale: billingLocaleSchema,
|
|
80
|
+
plan: billingCheckoutPlanSchema.default("pro"),
|
|
81
|
+
})
|
|
82
|
+
.strict();
|
|
83
|
+
export type BillingCreateCheckoutSessionInput = z.infer<
|
|
84
|
+
typeof billingCreateCheckoutSessionInputSchema
|
|
85
|
+
>;
|
|
72
86
|
|
|
73
|
-
export const billingCreateCustomerPortalSessionInputSchema = z
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
87
|
+
export const billingCreateCustomerPortalSessionInputSchema = z
|
|
88
|
+
.object({
|
|
89
|
+
locale: billingLocaleSchema,
|
|
90
|
+
})
|
|
91
|
+
.strict();
|
|
92
|
+
export type BillingCreateCustomerPortalSessionInput = z.infer<
|
|
93
|
+
typeof billingCreateCustomerPortalSessionInputSchema
|
|
94
|
+
>;
|
|
77
95
|
|
|
78
|
-
export const billingSessionUrlOutputSchema = z
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
96
|
+
export const billingSessionUrlOutputSchema = z
|
|
97
|
+
.object({
|
|
98
|
+
url: z.url(),
|
|
99
|
+
})
|
|
100
|
+
.strict();
|
|
101
|
+
export type BillingSessionUrlOutput = z.infer<typeof billingSessionUrlOutputSchema>;
|
|
82
102
|
|
|
83
|
-
export const billingCancelScheduledChangeOutputSchema = z
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
103
|
+
export const billingCancelScheduledChangeOutputSchema = z
|
|
104
|
+
.object({
|
|
105
|
+
success: z.literal(true),
|
|
106
|
+
})
|
|
107
|
+
.strict();
|
|
108
|
+
export type BillingCancelScheduledChangeOutput = z.infer<
|
|
109
|
+
typeof billingCancelScheduledChangeOutputSchema
|
|
110
|
+
>;
|
package/src/schemas/card.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
+
import { paginationShape, pageSchema } from "./pagination";
|
|
2
|
+
import { deletionResultSchema, expectedUpdatedAtSchema } from "./resource-mutation";
|
|
1
3
|
import {
|
|
2
4
|
cardIdentityShape,
|
|
3
5
|
cardMemoryStateShape,
|
|
4
6
|
cardStateSchema,
|
|
5
7
|
cardTemplateConfigSchema,
|
|
6
8
|
scheduleStatusSchema,
|
|
7
|
-
} from "@read-frog/definitions"
|
|
8
|
-
import { z } from "zod"
|
|
9
|
+
} from "@read-frog/definitions";
|
|
10
|
+
import { z } from "zod";
|
|
9
11
|
|
|
10
|
-
export {
|
|
11
|
-
|
|
12
|
-
scheduleStatusSchema,
|
|
13
|
-
}
|
|
14
|
-
export type { CardState, ScheduleStatus } from "@read-frog/definitions"
|
|
12
|
+
export { cardStateSchema, scheduleStatusSchema };
|
|
13
|
+
export type { CardState, ScheduleStatus } from "@read-frog/definitions";
|
|
15
14
|
|
|
16
15
|
export const cardTemplateSchema = z.object({
|
|
17
16
|
id: z.uuid(),
|
|
@@ -20,101 +19,105 @@ export const cardTemplateSchema = z.object({
|
|
|
20
19
|
config: cardTemplateConfigSchema,
|
|
21
20
|
createdAt: z.coerce.date(),
|
|
22
21
|
updatedAt: z.coerce.date(),
|
|
23
|
-
})
|
|
24
|
-
export type CardTemplate = z.infer<typeof cardTemplateSchema
|
|
22
|
+
});
|
|
23
|
+
export type CardTemplate = z.infer<typeof cardTemplateSchema>;
|
|
25
24
|
|
|
26
25
|
export const CardTemplateListInputSchema = z.object({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
...paginationShape,
|
|
27
|
+
notebaseId: z.uuid().optional(),
|
|
28
|
+
});
|
|
29
|
+
export type CardTemplateListInput = z.infer<typeof CardTemplateListInputSchema>;
|
|
30
30
|
|
|
31
|
-
export const CardTemplateListOutputSchema =
|
|
32
|
-
export type CardTemplateListOutput = z.infer<typeof CardTemplateListOutputSchema
|
|
31
|
+
export const CardTemplateListOutputSchema = pageSchema(cardTemplateSchema);
|
|
32
|
+
export type CardTemplateListOutput = z.infer<typeof CardTemplateListOutputSchema>;
|
|
33
33
|
|
|
34
34
|
export const CardTemplateGetInputSchema = z.object({
|
|
35
35
|
id: z.uuid(),
|
|
36
|
-
})
|
|
37
|
-
export type CardTemplateGetInput = z.infer<typeof CardTemplateGetInputSchema
|
|
38
|
-
|
|
39
|
-
export const CardTemplateGetOutputSchema = cardTemplateSchema
|
|
40
|
-
export type CardTemplateGetOutput = z.infer<typeof CardTemplateGetOutputSchema
|
|
41
|
-
|
|
42
|
-
export const CardTemplateCreateInputSchema = z
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
});
|
|
37
|
+
export type CardTemplateGetInput = z.infer<typeof CardTemplateGetInputSchema>;
|
|
38
|
+
|
|
39
|
+
export const CardTemplateGetOutputSchema = cardTemplateSchema;
|
|
40
|
+
export type CardTemplateGetOutput = z.infer<typeof CardTemplateGetOutputSchema>;
|
|
41
|
+
|
|
42
|
+
export const CardTemplateCreateInputSchema = z
|
|
43
|
+
.object({
|
|
44
|
+
id: z.uuid().optional(),
|
|
45
|
+
notebaseId: z.uuid(),
|
|
46
|
+
name: z.string().min(1),
|
|
47
|
+
config: cardTemplateConfigSchema,
|
|
48
|
+
})
|
|
49
|
+
.strict();
|
|
50
|
+
export type CardTemplateCreateInput = z.infer<typeof CardTemplateCreateInputSchema>;
|
|
49
51
|
|
|
50
52
|
export const CardTemplateCreateOutputSchema = cardTemplateSchema.extend({
|
|
51
53
|
txid: z.number(),
|
|
52
|
-
})
|
|
53
|
-
export type CardTemplateCreateOutput = z.infer<typeof CardTemplateCreateOutputSchema
|
|
54
|
-
|
|
55
|
-
export const CardTemplateUpdateInputSchema = z
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
});
|
|
55
|
+
export type CardTemplateCreateOutput = z.infer<typeof CardTemplateCreateOutputSchema>;
|
|
56
|
+
|
|
57
|
+
export const CardTemplateUpdateInputSchema = z
|
|
58
|
+
.object({
|
|
59
|
+
expectedUpdatedAt: expectedUpdatedAtSchema.optional(),
|
|
60
|
+
id: z.uuid(),
|
|
61
|
+
name: z.string().min(1).optional(),
|
|
62
|
+
config: cardTemplateConfigSchema.optional(),
|
|
63
|
+
})
|
|
64
|
+
.strict();
|
|
65
|
+
export type CardTemplateUpdateInput = z.infer<typeof CardTemplateUpdateInputSchema>;
|
|
61
66
|
|
|
62
67
|
export const CardTemplateUpdateOutputSchema = cardTemplateSchema.extend({
|
|
63
68
|
txid: z.number(),
|
|
64
|
-
})
|
|
65
|
-
export type CardTemplateUpdateOutput = z.infer<typeof CardTemplateUpdateOutputSchema
|
|
69
|
+
});
|
|
70
|
+
export type CardTemplateUpdateOutput = z.infer<typeof CardTemplateUpdateOutputSchema>;
|
|
66
71
|
|
|
67
72
|
export const CardTemplateDeleteInputSchema = z.object({
|
|
68
73
|
id: z.uuid(),
|
|
69
|
-
})
|
|
70
|
-
export type CardTemplateDeleteInput = z.infer<typeof CardTemplateDeleteInputSchema
|
|
74
|
+
});
|
|
75
|
+
export type CardTemplateDeleteInput = z.infer<typeof CardTemplateDeleteInputSchema>;
|
|
71
76
|
|
|
72
|
-
export const CardTemplateDeleteOutputSchema =
|
|
73
|
-
|
|
74
|
-
})
|
|
75
|
-
export type CardTemplateDeleteOutput = z.infer<typeof CardTemplateDeleteOutputSchema>
|
|
77
|
+
export const CardTemplateDeleteOutputSchema = deletionResultSchema;
|
|
78
|
+
export type CardTemplateDeleteOutput = z.infer<typeof CardTemplateDeleteOutputSchema>;
|
|
76
79
|
|
|
77
80
|
export const cardSchema = z.object({
|
|
78
81
|
...cardIdentityShape,
|
|
79
82
|
...cardMemoryStateShape,
|
|
80
83
|
createdAt: z.coerce.date(),
|
|
81
84
|
updatedAt: z.coerce.date(),
|
|
82
|
-
})
|
|
83
|
-
export type Card = z.infer<typeof cardSchema
|
|
85
|
+
});
|
|
86
|
+
export type Card = z.infer<typeof cardSchema>;
|
|
84
87
|
|
|
85
88
|
export const renderedCardSchema = cardSchema.extend({
|
|
86
89
|
front: z.string(),
|
|
87
90
|
back: z.string(),
|
|
88
|
-
})
|
|
89
|
-
export type RenderedCard = z.infer<typeof renderedCardSchema
|
|
91
|
+
});
|
|
92
|
+
export type RenderedCard = z.infer<typeof renderedCardSchema>;
|
|
90
93
|
|
|
91
94
|
export const CardListInputSchema = z.object({
|
|
92
|
-
notebaseId: z.uuid(),
|
|
95
|
+
notebaseId: z.uuid().optional(),
|
|
93
96
|
templateId: z.uuid().optional(),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
})
|
|
97
|
-
export type CardListInput = z.infer<typeof CardListInputSchema
|
|
97
|
+
scheduleStatus: scheduleStatusSchema.optional(),
|
|
98
|
+
...paginationShape,
|
|
99
|
+
});
|
|
100
|
+
export type CardListInput = z.infer<typeof CardListInputSchema>;
|
|
98
101
|
|
|
99
|
-
export const CardListOutputSchema =
|
|
100
|
-
export type CardListOutput = z.infer<typeof CardListOutputSchema
|
|
102
|
+
export const CardListOutputSchema = pageSchema(renderedCardSchema);
|
|
103
|
+
export type CardListOutput = z.infer<typeof CardListOutputSchema>;
|
|
101
104
|
|
|
102
105
|
export const CardGetInputSchema = z.object({
|
|
103
106
|
id: z.uuid(),
|
|
104
|
-
})
|
|
105
|
-
export type CardGetInput = z.infer<typeof CardGetInputSchema
|
|
107
|
+
});
|
|
108
|
+
export type CardGetInput = z.infer<typeof CardGetInputSchema>;
|
|
106
109
|
|
|
107
|
-
export const CardGetOutputSchema = renderedCardSchema
|
|
108
|
-
export type CardGetOutput = z.infer<typeof CardGetOutputSchema
|
|
110
|
+
export const CardGetOutputSchema = renderedCardSchema;
|
|
111
|
+
export type CardGetOutput = z.infer<typeof CardGetOutputSchema>;
|
|
109
112
|
|
|
110
113
|
export const CardGenerateInputSchema = z.object({
|
|
111
114
|
notebaseId: z.uuid(),
|
|
112
115
|
templateId: z.uuid().optional(),
|
|
113
|
-
})
|
|
114
|
-
export type CardGenerateInput = z.infer<typeof CardGenerateInputSchema
|
|
116
|
+
});
|
|
117
|
+
export type CardGenerateInput = z.infer<typeof CardGenerateInputSchema>;
|
|
115
118
|
|
|
116
119
|
export const CardGenerateOutputSchema = z.object({
|
|
117
120
|
created: z.number().int().min(0),
|
|
118
121
|
txid: z.number(),
|
|
119
|
-
})
|
|
120
|
-
export type CardGenerateOutput = z.infer<typeof CardGenerateOutputSchema
|
|
122
|
+
});
|
|
123
|
+
export type CardGenerateOutput = z.infer<typeof CardGenerateOutputSchema>;
|