1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-04 21:15:22 +02:00

chore: file generation cleanup (#1736)

This PR does too many things :( 

1. Major refactoring of the dev/scripts and dev/code-generation folders. 

Primarily this was removing duplicate code and cleaning up some poorly written code snippets as well as making them more idempotent so then can be re-run over and over again but still maintain the same results. This is working on my machine, but I've been having problems in CI and comparing diffs so running generators in CI will have to wait. 

2. Re-Implement using the generated api routes for testing

This was a _huge_ refactor that touched damn near every test file but now we have auto-generated typed routes with inline hints and it's used for nearly every test excluding a few that use classes for better parameterization. This should greatly reduce errors when writing new tests. 

3. Minor Perf improvements for the All Recipes endpoint

  A. Removed redundant loops
  B. Uses orjson to do the encoding directly and returns a byte response instead of relying on the default 
       jsonable_encoder.

4. Fix some TS type errors that cropped up for seemingly no reason half way through the PR.

See this issue https://github.com/phillipdupuis/pydantic-to-typescript/issues/28

Basically, the generated TS type is not-correct since Pydantic will automatically fill in null fields. The resulting TS type is generated with a ? to indicate it can be null even though we _know_ that i can't be.
This commit is contained in:
Hayden 2022-10-18 14:49:41 -08:00 committed by GitHub
parent a8f0fb14a7
commit 9ecef4c25f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
107 changed files with 2520 additions and 1948 deletions

View file

@ -133,6 +133,9 @@ export interface RecipeIngredient {
export interface IngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
@ -143,6 +146,9 @@ export interface IngredientUnit {
export interface CreateIngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
@ -150,6 +156,9 @@ export interface CreateIngredientUnit {
export interface IngredientFood {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
labelId?: string;
id: string;
label?: MultiPurposeLabelSummary;
@ -165,6 +174,9 @@ export interface MultiPurposeLabelSummary {
export interface CreateIngredientFood {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
labelId?: string;
}
export interface CustomPageImport {

View file

@ -5,11 +5,6 @@
/* Do not modify it by hand - just update the pydantic models and then re-run the script
*/
export interface CategoryBase {
name: string;
id: string;
slug: string;
}
export interface CreateCookBook {
name: string;
description?: string;
@ -23,6 +18,11 @@ export interface CreateCookBook {
requireAllTags?: boolean;
requireAllTools?: boolean;
}
export interface CategoryBase {
name: string;
id: string;
slug: string;
}
export interface TagBase {
name: string;
id: string;
@ -112,6 +112,9 @@ export interface RecipeIngredient {
export interface IngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
@ -122,6 +125,9 @@ export interface IngredientUnit {
export interface CreateIngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
@ -129,6 +135,9 @@ export interface CreateIngredientUnit {
export interface IngredientFood {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
labelId?: string;
id: string;
label?: MultiPurposeLabelSummary;
@ -144,6 +153,9 @@ export interface MultiPurposeLabelSummary {
export interface CreateIngredientFood {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
labelId?: string;
}
export interface SaveCookBook {

View file

@ -73,6 +73,8 @@ export interface GroupEventNotifierCreate {
* If you modify this, make sure to update the EventBusService as well.
*/
export interface GroupEventNotifierOptions {
testMessage?: boolean;
webhookTask?: boolean;
recipeCreated?: boolean;
recipeUpdated?: boolean;
recipeDeleted?: boolean;
@ -99,6 +101,8 @@ export interface GroupEventNotifierOptions {
* If you modify this, make sure to update the EventBusService as well.
*/
export interface GroupEventNotifierOptionsOut {
testMessage?: boolean;
webhookTask?: boolean;
recipeCreated?: boolean;
recipeUpdated?: boolean;
recipeDeleted?: boolean;
@ -126,6 +130,8 @@ export interface GroupEventNotifierOptionsOut {
* If you modify this, make sure to update the EventBusService as well.
*/
export interface GroupEventNotifierOptionsSave {
testMessage?: boolean;
webhookTask?: boolean;
recipeCreated?: boolean;
recipeUpdated?: boolean;
recipeDeleted?: boolean;
@ -191,31 +197,6 @@ export interface GroupStorage {
totalStorageBytes: number;
totalStorageStr: string;
}
export interface IngredientFood {
name: string;
description?: string;
labelId?: string;
id: string;
label?: MultiPurposeLabelSummary;
createdAt?: string;
updateAt?: string;
}
export interface MultiPurposeLabelSummary {
name: string;
color?: string;
groupId: string;
id: string;
}
export interface IngredientUnit {
name: string;
description?: string;
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
id: string;
createdAt?: string;
updateAt?: string;
}
export interface ReadGroupPreferences {
privateGroup?: boolean;
firstDayOfWeek?: number;
@ -242,6 +223,156 @@ export interface ReadWebhook {
groupId: string;
id: string;
}
export interface SaveInviteToken {
usesLeft: number;
groupId: string;
token: string;
}
export interface SaveWebhook {
enabled?: boolean;
name?: string;
url?: string;
webhookType?: WebhookType & string;
scheduledTime: string;
groupId: string;
}
export interface SeederConfig {
locale: string;
}
export interface SetPermissions {
userId: string;
canManage?: boolean;
canInvite?: boolean;
canOrganize?: boolean;
}
export interface ShoppingListCreate {
name?: string;
extras?: {
[k: string]: unknown;
};
createdAt?: string;
updateAt?: string;
}
export interface ShoppingListItemCreate {
shoppingListId: string;
checked?: boolean;
position?: number;
isFood?: boolean;
note?: string;
quantity?: number;
unitId?: string;
unit?: IngredientUnit;
foodId?: string;
food?: IngredientFood;
labelId?: string;
recipeReferences?: ShoppingListItemRecipeRef[];
extras?: {
[k: string]: unknown;
};
createdAt?: string;
updateAt?: string;
}
export interface IngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
id: string;
createdAt?: string;
updateAt?: string;
}
export interface IngredientFood {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
labelId?: string;
id: string;
label?: MultiPurposeLabelSummary;
createdAt?: string;
updateAt?: string;
}
export interface MultiPurposeLabelSummary {
name: string;
color?: string;
groupId: string;
id: string;
}
export interface ShoppingListItemRecipeRef {
recipeId: string;
recipeQuantity?: number;
}
export interface ShoppingListItemOut {
shoppingListId: string;
checked?: boolean;
position?: number;
isFood?: boolean;
note?: string;
quantity?: number;
unitId?: string;
unit?: IngredientUnit;
foodId?: string;
food?: IngredientFood;
labelId?: string;
recipeReferences?: (ShoppingListItemRecipeRef | ShoppingListItemRecipeRefOut)[];
extras?: {
[k: string]: unknown;
};
createdAt?: string;
updateAt?: string;
id: string;
label?: MultiPurposeLabelSummary;
}
export interface ShoppingListItemRecipeRefOut {
recipeId: string;
recipeQuantity?: number;
id: string;
shoppingListItemId: string;
}
export interface ShoppingListItemUpdate {
shoppingListId: string;
checked?: boolean;
position?: number;
isFood?: boolean;
note?: string;
quantity?: number;
unitId?: string;
unit?: IngredientUnit;
foodId?: string;
food?: IngredientFood;
labelId?: string;
recipeReferences?: ShoppingListItemRecipeRef[];
extras?: {
[k: string]: unknown;
};
createdAt?: string;
updateAt?: string;
id: string;
}
export interface ShoppingListOut {
name?: string;
extras?: {
[k: string]: unknown;
};
createdAt?: string;
updateAt?: string;
groupId: string;
id: string;
listItems?: ShoppingListItemOut[];
recipeReferences: ShoppingListRecipeRefOut[];
}
export interface ShoppingListRecipeRefOut {
id: string;
shoppingListId: string;
recipeId: string;
recipeQuantity: number;
recipe: RecipeSummary;
}
export interface RecipeSummary {
id?: string;
userId?: string;
@ -295,6 +426,9 @@ export interface RecipeIngredient {
export interface CreateIngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
@ -302,120 +436,25 @@ export interface CreateIngredientUnit {
export interface CreateIngredientFood {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
labelId?: string;
}
export interface SaveInviteToken {
usesLeft: number;
groupId: string;
token: string;
}
export interface SaveWebhook {
enabled?: boolean;
name?: string;
url?: string;
webhookType?: WebhookType & string;
scheduledTime: string;
groupId: string;
}
export interface SeederConfig {
locale: string;
}
export interface SetPermissions {
userId: string;
canManage?: boolean;
canInvite?: boolean;
canOrganize?: boolean;
}
export interface ShoppingListCreate {
name?: string;
createdAt?: string;
updateAt?: string;
}
export interface ShoppingListItemCreate {
shoppingListId: string;
checked?: boolean;
position?: number;
isFood?: boolean;
note?: string;
quantity?: number;
unitId?: string;
unit?: IngredientUnit;
foodId?: string;
food?: IngredientFood;
labelId?: string;
recipeReferences?: ShoppingListItemRecipeRef[];
createdAt?: string;
updateAt?: string;
}
export interface ShoppingListItemRecipeRef {
recipeId: string;
recipeQuantity: number;
}
export interface ShoppingListItemOut {
shoppingListId: string;
checked?: boolean;
position?: number;
isFood?: boolean;
note?: string;
quantity?: number;
unitId?: string;
unit?: IngredientUnit;
foodId?: string;
food?: IngredientFood;
labelId?: string;
recipeReferences?: (ShoppingListItemRecipeRef | ShoppingListItemRecipeRefOut)[];
createdAt?: string;
updateAt?: string;
id: string;
label?: MultiPurposeLabelSummary;
}
export interface ShoppingListItemRecipeRefOut {
recipeId: string;
recipeQuantity: number;
id: string;
shoppingListItemId: string;
}
export interface ShoppingListItemUpdate {
shoppingListId: string;
checked?: boolean;
position?: number;
isFood?: boolean;
note?: string;
quantity?: number;
unitId?: string;
unit?: IngredientUnit;
foodId?: string;
food?: IngredientFood;
labelId?: string;
recipeReferences?: ShoppingListItemRecipeRef[];
createdAt?: string;
updateAt?: string;
id: string;
}
export interface ShoppingListOut {
name?: string;
createdAt?: string;
updateAt?: string;
groupId: string;
id: string;
listItems?: ShoppingListItemOut[];
recipeReferences: ShoppingListRecipeRefOut[];
}
export interface ShoppingListRecipeRefOut {
id: string;
shoppingListId: string;
recipeId: string;
recipeQuantity: number;
recipe: RecipeSummary;
}
export interface ShoppingListSave {
name?: string;
extras?: {
[k: string]: unknown;
};
createdAt?: string;
updateAt?: string;
groupId: string;
}
export interface ShoppingListSummary {
name?: string;
extras?: {
[k: string]: unknown;
};
createdAt?: string;
updateAt?: string;
groupId: string;
@ -423,6 +462,9 @@ export interface ShoppingListSummary {
}
export interface ShoppingListUpdate {
name?: string;
extras?: {
[k: string]: unknown;
};
createdAt?: string;
updateAt?: string;
groupId: string;

View file

@ -148,6 +148,9 @@ export interface RecipeIngredient {
export interface IngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
@ -158,6 +161,9 @@ export interface IngredientUnit {
export interface CreateIngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
@ -165,6 +171,9 @@ export interface CreateIngredientUnit {
export interface IngredientFood {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
labelId?: string;
id: string;
label?: MultiPurposeLabelSummary;
@ -180,6 +189,9 @@ export interface MultiPurposeLabelSummary {
export interface CreateIngredientFood {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
labelId?: string;
}
export interface SavePlanEntry {

View file

@ -5,17 +5,21 @@
/* Do not modify it by hand - just update the pydantic models and then re-run the script
*/
export interface OcrTsvResponse {
level: number;
pageNum: number;
blockNum: number;
parNum: number;
lineNum: number;
wordNum: number;
left: number;
top: number;
width: number;
height: number;
conf: number;
text: string;
export interface OcrAssetReq {
recipeSlug: string;
assetName: string;
}
export interface OcrTsvResponse {
level?: number;
pageNum?: number;
blockNum?: number;
parNum?: number;
lineNum?: number;
wordNum?: number;
left?: number;
top?: number;
width?: number;
height?: number;
conf?: number;
text?: string;
}

View file

@ -56,11 +56,17 @@ export interface CategorySave {
export interface CreateIngredientFood {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
labelId?: string;
}
export interface CreateIngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
@ -107,6 +113,9 @@ export interface IngredientConfidence {
export interface IngredientFood {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
labelId?: string;
id: string;
label?: MultiPurposeLabelSummary;
@ -132,6 +141,9 @@ export interface IngredientRequest {
export interface IngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
@ -160,13 +172,6 @@ export interface Nutrition {
sodiumContent?: string;
sugarContent?: string;
}
export interface PaginationQuery {
page?: number;
perPage?: number;
orderBy?: string;
orderDirection?: OrderDirection & string;
queryFilter?: string;
}
export interface ParsedIngredient {
input?: string;
confidence?: IngredientConfidence;
@ -213,8 +218,8 @@ export interface Recipe {
extras?: {
[k: string]: unknown;
};
comments?: RecipeCommentOut[];
isOcrRecipe?: boolean;
comments?: RecipeCommentOut[];
}
export interface RecipeTool {
id: string;
@ -335,16 +340,16 @@ export interface RecipeTagResponse {
slug: string;
recipes?: RecipeSummary[];
}
export interface RecipeTool1 {
export interface RecipeToolCreate {
name: string;
onHand?: boolean;
}
export interface RecipeToolOut {
name: string;
onHand?: boolean;
id: string;
slug: string;
}
export interface RecipeToolCreate {
name: string;
onHand?: boolean;
}
export interface RecipeToolResponse {
name: string;
onHand?: boolean;
@ -363,12 +368,18 @@ export interface RecipeZipTokenResponse {
export interface SaveIngredientFood {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
labelId?: string;
groupId: string;
}
export interface SaveIngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
@ -398,7 +409,17 @@ export interface TagSave {
export interface UnitFoodBase {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
}
export interface UpdateImageResponse {
image: string;
}
export interface PaginationQuery {
page?: number;
perPage?: number;
orderBy?: string;
orderDirection?: OrderDirection & string;
queryFilter?: string;
}

View file

@ -5,6 +5,8 @@
/* Do not modify it by hand - just update the pydantic models and then re-run the script
*/
export type OrderDirection = "asc" | "desc";
export interface ErrorResponse {
message: string;
error?: boolean;
@ -13,6 +15,13 @@ export interface ErrorResponse {
export interface FileTokenResponse {
fileToken: string;
}
export interface PaginationQuery {
page?: number;
perPage?: number;
orderBy?: string;
orderDirection?: OrderDirection & string;
queryFilter?: string;
}
export interface SuccessResponse {
message: string;
error?: boolean;

View file

@ -5,17 +5,13 @@
/* Do not modify it by hand - just update the pydantic models and then re-run the script
*/
export interface CategoryBase {
name: string;
id: string;
slug: string;
}
export interface ChangePassword {
currentPassword: string;
newPassword: string;
}
export interface CreateToken {
name: string;
integrationId?: string;
userId: string;
token: string;
}
@ -48,6 +44,11 @@ export interface GroupInDB {
users?: UserOut[];
preferences?: ReadGroupPreferences;
}
export interface CategoryBase {
name: string;
id: string;
slug: string;
}
export interface UserOut {
username?: string;
fullName?: string;
@ -83,9 +84,11 @@ export interface ReadGroupPreferences {
}
export interface LongLiveTokenIn {
name: string;
integrationId?: string;
}
export interface LongLiveTokenInDB {
name: string;
integrationId?: string;
userId: string;
token: string;
id: number;
@ -115,6 +118,57 @@ export interface PrivatePasswordResetToken {
token: string;
user: PrivateUser;
}
export interface ResetPassword {
token: string;
email: string;
password: string;
passwordConfirm: string;
}
export interface SavePasswordResetToken {
userId: string;
token: string;
}
export interface Token {
access_token: string;
token_type: string;
}
export interface TokenData {
user_id?: string;
username?: string;
}
export interface UnlockResults {
unlocked?: number;
}
export interface UpdateGroup {
name: string;
id: string;
categories?: CategoryBase[];
webhooks?: unknown[];
}
export interface UserBase {
username?: string;
fullName?: string;
email: string;
admin?: boolean;
group?: string;
advanced?: boolean;
favoriteRecipes?: string[];
canInvite?: boolean;
canManage?: boolean;
canOrganize?: boolean;
}
export interface UserFavorites {
username?: string;
fullName?: string;
email: string;
admin?: boolean;
group?: string;
advanced?: boolean;
favoriteRecipes?: RecipeSummary[];
canInvite?: boolean;
canManage?: boolean;
canOrganize?: boolean;
}
export interface RecipeSummary {
id?: string;
userId?: string;
@ -168,6 +222,9 @@ export interface RecipeIngredient {
export interface IngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
@ -178,6 +235,9 @@ export interface IngredientUnit {
export interface CreateIngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
@ -185,6 +245,9 @@ export interface CreateIngredientUnit {
export interface IngredientFood {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
labelId?: string;
id: string;
label?: MultiPurposeLabelSummary;
@ -200,59 +263,11 @@ export interface MultiPurposeLabelSummary {
export interface CreateIngredientFood {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
labelId?: string;
}
export interface ResetPassword {
token: string;
email: string;
password: string;
passwordConfirm: string;
}
export interface SavePasswordResetToken {
userId: string;
token: string;
}
export interface Token {
access_token: string;
token_type: string;
}
export interface TokenData {
user_id?: string;
username?: string;
}
export interface UnlockResults {
unlocked?: number;
}
export interface UpdateGroup {
name: string;
id: string;
categories?: CategoryBase[];
webhooks?: unknown[];
}
export interface UserBase {
username?: string;
fullName?: string;
email: string;
admin?: boolean;
group?: string;
advanced?: boolean;
favoriteRecipes?: string[];
canInvite?: boolean;
canManage?: boolean;
canOrganize?: boolean;
}
export interface UserFavorites {
username?: string;
fullName?: string;
email: string;
admin?: boolean;
group?: string;
advanced?: boolean;
favoriteRecipes?: RecipeSummary[];
canInvite?: boolean;
canManage?: boolean;
canOrganize?: boolean;
}
export interface UserIn {
username?: string;
fullName?: string;