From 0f6cda377c1ef621d61309422bfd86e0635a008d Mon Sep 17 00:00:00 2001
From: imperosol <thgirod@hotmail.com>
Date: Wed, 5 Mar 2025 12:45:56 +0100
Subject: [PATCH] Fix paginated TS interfaces

---
 core/static/bundled/utils/api.ts      | 8 +++++---
 sas/static/bundled/sas/album-index.ts | 3 ++-
 tsconfig.json                         | 5 ++---
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/core/static/bundled/utils/api.ts b/core/static/bundled/utils/api.ts
index 5d72b3b6..af68511b 100644
--- a/core/static/bundled/utils/api.ts
+++ b/core/static/bundled/utils/api.ts
@@ -1,4 +1,4 @@
-import type { Client, Options, RequestResult } from "@hey-api/client-fetch";
+import type { Client, Options, RequestResult, TDataShape } from "@hey-api/client-fetch";
 import { client } from "#openapi";
 
 export interface PaginatedResponse<T> {
@@ -14,6 +14,7 @@ export interface PaginatedRequest {
     // biome-ignore lint/style/useNamingConvention: api is in snake_case
     page_size?: number;
   };
+  url: string;
 }
 
 type PaginatedEndpoint<T> = <ThrowOnError extends boolean = false>(
@@ -30,7 +31,7 @@ export const paginated = async <T>(
   options?: PaginatedRequest,
 ): Promise<T[]> => {
   const maxPerPage = 199;
-  const queryParams = options ?? {};
+  const queryParams = options ?? ({} as PaginatedRequest);
   queryParams.query = queryParams.query ?? {};
   queryParams.query.page_size = maxPerPage;
   queryParams.query.page = 1;
@@ -53,8 +54,9 @@ export const paginated = async <T>(
   return results;
 };
 
-interface Request {
+interface Request extends TDataShape {
   client?: Client;
+  url: string;
 }
 
 interface InterceptorOptions {
diff --git a/sas/static/bundled/sas/album-index.ts b/sas/static/bundled/sas/album-index.ts
index c04df038..02e19fc9 100644
--- a/sas/static/bundled/sas/album-index.ts
+++ b/sas/static/bundled/sas/album-index.ts
@@ -1,6 +1,7 @@
 import { paginated } from "#core:utils/api";
 import { History, initialUrlParams, updateQueryString } from "#core:utils/history";
 import {
+  type AlbumFetchAlbumData,
   type AlbumSchema,
   type PictureSchema,
   type PicturesFetchPicturesData,
@@ -77,7 +78,7 @@ document.addEventListener("alpine:init", () => {
       this.albums = await paginated(albumFetchAlbum, {
         // biome-ignore lint/style/useNamingConvention: API is snake_case
         query: { parent_id: this.config.parentId },
-      });
+      } as AlbumFetchAlbumData);
       this.loading = false;
     },
   }));
diff --git a/tsconfig.json b/tsconfig.json
index e632cc80..d0741918 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -3,8 +3,8 @@
     "outDir": "./staticfiles/generated/bundled/",
     "sourceMap": true,
     "noImplicitAny": true,
-    "module": "es6",
-    "target": "es6",
+    "module": "esnext",
+    "target": "es2022",
     "allowJs": true,
     "moduleResolution": "node",
     "experimentalDecorators": true,
@@ -12,7 +12,6 @@
     "esModuleInterop": true,
     "resolveJsonModule": true,
     "types": ["jquery", "alpinejs"],
-    "lib": ["es7"],
     "paths": {
       "#openapi": ["./staticfiles/generated/openapi/client/index.ts"],
       "#core:*": ["./core/static/bundled/*"],