From bf8db7314f7c7eecac4b41d8f46bed17c3f98b76 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 1 Nov 2024 14:49:46 +0000 Subject: [PATCH] chore: rebuild project due to codegen change (#42) --- internal/pagination/pagination.go | 110 ------------------------------ 1 file changed, 110 deletions(-) delete mode 100644 internal/pagination/pagination.go diff --git a/internal/pagination/pagination.go b/internal/pagination/pagination.go deleted file mode 100644 index 7e71cb9..0000000 --- a/internal/pagination/pagination.go +++ /dev/null @@ -1,110 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -package pagination - -import ( - "net/http" - - "github.com/Metronome-Industries/metronome-go/internal/apijson" - "github.com/Metronome-Industries/metronome-go/internal/requestconfig" - "github.com/Metronome-Industries/metronome-go/option" -) - -type CursorPage[T any] struct { - // Cursor to fetch the next page - NextPage string `json:"next_page"` - // Items of the page - Data []T `json:"data"` - JSON cursorPageJSON `json:"-"` - cfg *requestconfig.RequestConfig - res *http.Response -} - -// cursorPageJSON contains the JSON metadata for the struct [CursorPage[T]] -type cursorPageJSON struct { - NextPage apijson.Field - Data apijson.Field - raw string - ExtraFields map[string]apijson.Field -} - -func (r *CursorPage[T]) UnmarshalJSON(data []byte) (err error) { - return apijson.UnmarshalRoot(data, r) -} - -func (r cursorPageJSON) RawJSON() string { - return r.raw -} - -// GetNextPage returns the next page as defined by this pagination style. When -// there is no next page, this function will return a 'nil' for the page value, but -// will not return an error -func (r *CursorPage[T]) GetNextPage() (res *CursorPage[T], err error) { - next := r.NextPage - if len(next) == 0 { - return nil, nil - } - cfg := r.cfg.Clone(r.cfg.Context) - cfg.Apply(option.WithQuery("next_page", next)) - var raw *http.Response - cfg.ResponseInto = &raw - cfg.ResponseBodyInto = &res - err = cfg.Execute() - if err != nil { - return nil, err - } - res.SetPageConfig(cfg, raw) - return res, nil -} - -func (r *CursorPage[T]) SetPageConfig(cfg *requestconfig.RequestConfig, res *http.Response) { - if r == nil { - r = &CursorPage[T]{} - } - r.cfg = cfg - r.res = res -} - -type CursorPageAutoPager[T any] struct { - page *CursorPage[T] - cur T - idx int - run int - err error -} - -func NewCursorPageAutoPager[T any](page *CursorPage[T], err error) *CursorPageAutoPager[T] { - return &CursorPageAutoPager[T]{ - page: page, - err: err, - } -} - -func (r *CursorPageAutoPager[T]) Next() bool { - if r.page == nil || len(r.page.Data) == 0 { - return false - } - if r.idx >= len(r.page.Data) { - r.idx = 0 - r.page, r.err = r.page.GetNextPage() - if r.err != nil || r.page == nil || len(r.page.Data) == 0 { - return false - } - } - r.cur = r.page.Data[r.idx] - r.run += 1 - r.idx += 1 - return true -} - -func (r *CursorPageAutoPager[T]) Current() T { - return r.cur -} - -func (r *CursorPageAutoPager[T]) Err() error { - return r.err -} - -func (r *CursorPageAutoPager[T]) Index() int { - return r.run -}