refactor: make piefed adaptor (adapter?) declarative
This commit is contained in:
4 files changed
+774
-958
No files matched your search
@@ -84,7 +84,7 @@ export function client({
|
|||||||
return new Client(instanceToURL(instanceURL), {
|
return new Client(instanceToURL(instanceURL), {
|
||||||
fetchFunction: (input, init) => customFetch(func, input, init, jwt),
|
fetchFunction: (input, init) => customFetch(func, input, init, jwt),
|
||||||
headers: headers,
|
headers: headers,
|
||||||
}) as BaseClient
|
}) as unknown as BaseClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// here for parts where i forgor to switch
|
// here for parts where i forgor to switch
|
||||||
|
|||||||
+742
-903
File diff suppressed because it is too large.
Load diff
@@ -1,31 +1,4 @@
|
|||||||
import { Search } from 'mono-svelte'
|
import * as base from '../types'
|
||||||
import type {
|
|
||||||
Comment,
|
|
||||||
CommentReplyView,
|
|
||||||
CommentSortType,
|
|
||||||
CommentView,
|
|
||||||
Community,
|
|
||||||
CommunityView,
|
|
||||||
CreateComment,
|
|
||||||
CreatePost,
|
|
||||||
FeedView,
|
|
||||||
GetComments,
|
|
||||||
GetPost,
|
|
||||||
GetPosts,
|
|
||||||
GetReplies,
|
|
||||||
ListCommunities,
|
|
||||||
LocalSite,
|
|
||||||
MyUserInfo,
|
|
||||||
Person,
|
|
||||||
PersonMentionView,
|
|
||||||
PersonView,
|
|
||||||
Post,
|
|
||||||
PostView,
|
|
||||||
PrivateMessageView,
|
|
||||||
SortType,
|
|
||||||
SubscribedType,
|
|
||||||
TopicView,
|
|
||||||
} from '../types'
|
|
||||||
import type { components } from './schema'
|
import type { components } from './schema'
|
||||||
|
|
||||||
export function toPersonView(
|
export function toPersonView(
|
||||||
@@ -38,7 +11,7 @@ export function toPersonView(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toPerson(person: components['schemas']['Person']): Person {
|
export function toPerson(person: components['schemas']['Person']): base.Person {
|
||||||
return {
|
return {
|
||||||
...person,
|
...person,
|
||||||
id: person.id,
|
id: person.id,
|
||||||
@@ -47,14 +20,16 @@ export function toPerson(person: components['schemas']['Person']): Person {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toLocalSite(site: components['schemas']['Site']): LocalSite {
|
export function toLocalSite(
|
||||||
|
site: components['schemas']['Site'],
|
||||||
|
): base.LocalSite {
|
||||||
if (site) return {}
|
if (site) return {}
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toCommunityView(
|
export function toCommunityView(
|
||||||
communityView: components['schemas']['CommunityView'],
|
communityView: components['schemas']['CommunityView'],
|
||||||
): CommunityView {
|
): base.CommunityView {
|
||||||
return {
|
return {
|
||||||
...communityView,
|
...communityView,
|
||||||
community: toCommunity(communityView.community),
|
community: toCommunity(communityView.community),
|
||||||
@@ -76,7 +51,7 @@ export function toCommunityView(
|
|||||||
|
|
||||||
export function toCommunity(
|
export function toCommunity(
|
||||||
community: components['schemas']['Community'],
|
community: components['schemas']['Community'],
|
||||||
): Community {
|
): base.Community {
|
||||||
return {
|
return {
|
||||||
...community,
|
...community,
|
||||||
posting_restricted_to_mods: false,
|
posting_restricted_to_mods: false,
|
||||||
@@ -86,7 +61,7 @@ export function toCommunity(
|
|||||||
|
|
||||||
export function toMyUser(
|
export function toMyUser(
|
||||||
myUser: components['schemas']['MyUserInfo'],
|
myUser: components['schemas']['MyUserInfo'],
|
||||||
): MyUserInfo {
|
): base.MyUserInfo {
|
||||||
return {
|
return {
|
||||||
...myUser,
|
...myUser,
|
||||||
community_blocks: myUser.community_blocks.map((i) => ({
|
community_blocks: myUser.community_blocks.map((i) => ({
|
||||||
@@ -127,7 +102,7 @@ export function toMyUser(
|
|||||||
|
|
||||||
export function toPostView(
|
export function toPostView(
|
||||||
postView: components['schemas']['PostView'],
|
postView: components['schemas']['PostView'],
|
||||||
): PostView {
|
): base.PostView {
|
||||||
return {
|
return {
|
||||||
...postView,
|
...postView,
|
||||||
creator: toPerson(postView.creator),
|
creator: toPerson(postView.creator),
|
||||||
@@ -149,7 +124,7 @@ export function toPost(post: components['schemas']['Post']): Post {
|
|||||||
|
|
||||||
export function toCommentView(
|
export function toCommentView(
|
||||||
commentView: components['schemas']['CommentView'],
|
commentView: components['schemas']['CommentView'],
|
||||||
): CommentView {
|
): base.CommentView {
|
||||||
return {
|
return {
|
||||||
...commentView,
|
...commentView,
|
||||||
comment: toComment(commentView.comment),
|
comment: toComment(commentView.comment),
|
||||||
@@ -171,7 +146,7 @@ export function toComment(comment: components['schemas']['Comment']): Comment {
|
|||||||
|
|
||||||
export function toCommentReplyView(
|
export function toCommentReplyView(
|
||||||
commentReplyView: components['schemas']['CommentReplyView'],
|
commentReplyView: components['schemas']['CommentReplyView'],
|
||||||
): CommentReplyView {
|
): base.CommentReplyView {
|
||||||
return {
|
return {
|
||||||
...commentReplyView,
|
...commentReplyView,
|
||||||
banned_from_community: false,
|
banned_from_community: false,
|
||||||
@@ -186,7 +161,7 @@ export function toCommentReplyView(
|
|||||||
|
|
||||||
export function toPrivateMessageView(
|
export function toPrivateMessageView(
|
||||||
privateMessageView: components['schemas']['PrivateMessageView'],
|
privateMessageView: components['schemas']['PrivateMessageView'],
|
||||||
): PrivateMessageView {
|
): base.PrivateMessageView {
|
||||||
return {
|
return {
|
||||||
...privateMessageView,
|
...privateMessageView,
|
||||||
creator: toPerson(privateMessageView.creator),
|
creator: toPerson(privateMessageView.creator),
|
||||||
@@ -196,7 +171,7 @@ export function toPrivateMessageView(
|
|||||||
|
|
||||||
export function toPersonMentionView(
|
export function toPersonMentionView(
|
||||||
personMentionView: components['schemas']['CommentReplyView'],
|
personMentionView: components['schemas']['CommentReplyView'],
|
||||||
): PersonMentionView {
|
): base.PersonMentionView {
|
||||||
return {
|
return {
|
||||||
...personMentionView,
|
...personMentionView,
|
||||||
person_mention: personMentionView.comment_reply,
|
person_mention: personMentionView.comment_reply,
|
||||||
@@ -212,7 +187,7 @@ export function toPersonMentionView(
|
|||||||
|
|
||||||
export function toTopicView(
|
export function toTopicView(
|
||||||
topicView: components['schemas']['TopicView'],
|
topicView: components['schemas']['TopicView'],
|
||||||
): TopicView {
|
): base.TopicView {
|
||||||
return {
|
return {
|
||||||
...topicView,
|
...topicView,
|
||||||
communities: topicView.communities?.map(toCommunity),
|
communities: topicView.communities?.map(toCommunity),
|
||||||
@@ -222,7 +197,7 @@ export function toTopicView(
|
|||||||
|
|
||||||
export function toFeedView(
|
export function toFeedView(
|
||||||
feedView: components['schemas']['FeedView'],
|
feedView: components['schemas']['FeedView'],
|
||||||
): FeedView {
|
): base.FeedView {
|
||||||
return {
|
return {
|
||||||
...feedView,
|
...feedView,
|
||||||
communities: feedView.communities?.map(toCommunity),
|
communities: feedView.communities?.map(toCommunity),
|
||||||
@@ -232,7 +207,7 @@ export function toFeedView(
|
|||||||
|
|
||||||
// Query calls
|
// Query calls
|
||||||
export function fromGetPosts(
|
export function fromGetPosts(
|
||||||
getPosts: GetPosts,
|
getPosts: base.GetPosts,
|
||||||
): components['parameters']['GetPosts'] {
|
): components['parameters']['GetPosts'] {
|
||||||
return {
|
return {
|
||||||
...getPosts,
|
...getPosts,
|
||||||
@@ -242,7 +217,7 @@ export function fromGetPosts(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function fromGetComments(
|
export function fromGetComments(
|
||||||
getComments: GetComments,
|
getComments: base.GetComments,
|
||||||
): components['schemas']['GetComments'] {
|
): components['schemas']['GetComments'] {
|
||||||
return {
|
return {
|
||||||
...getComments,
|
...getComments,
|
||||||
@@ -251,13 +226,13 @@ export function fromGetComments(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function fromGetPost(
|
export function fromGetPost(
|
||||||
getPost: GetPost,
|
getPost: base.GetPost,
|
||||||
): components['schemas']['GetPost'] {
|
): components['schemas']['GetPost'] {
|
||||||
return getPost
|
return getPost
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fromGetReplies(
|
export function fromGetReplies(
|
||||||
getReplies: GetReplies,
|
getReplies: base.GetReplies,
|
||||||
): components['schemas']['GetReplies'] {
|
): components['schemas']['GetReplies'] {
|
||||||
return {
|
return {
|
||||||
...getReplies,
|
...getReplies,
|
||||||
@@ -265,9 +240,11 @@ export function fromGetReplies(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fromSearch(search: Search): components['schemas']['Search'] {
|
export function fromSearch(
|
||||||
|
search: base.Search,
|
||||||
|
): components['schemas']['Search'] {
|
||||||
return {
|
return {
|
||||||
...(search as Omit<Search, 'type_'> & {
|
...(search as Omit<base.Search, 'type_'> & {
|
||||||
type_: 'Communities' | 'Users' | 'Url' | 'Posts'
|
type_: 'Communities' | 'Users' | 'Url' | 'Posts'
|
||||||
}),
|
}),
|
||||||
sort: toSortType(search.sort),
|
sort: toSortType(search.sort),
|
||||||
@@ -275,7 +252,7 @@ export function fromSearch(search: Search): components['schemas']['Search'] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function fromCreatePost(
|
export function fromCreatePost(
|
||||||
createPost: CreatePost,
|
createPost: base.CreatePost,
|
||||||
): components['schemas']['CreatePost'] {
|
): components['schemas']['CreatePost'] {
|
||||||
return {
|
return {
|
||||||
...createPost,
|
...createPost,
|
||||||
@@ -284,7 +261,7 @@ export function fromCreatePost(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function fromListCommunities(
|
export function fromListCommunities(
|
||||||
listCommunities: ListCommunities,
|
listCommunities: base.ListCommunities,
|
||||||
): components['schemas']['CommunityRequest'] {
|
): components['schemas']['CommunityRequest'] {
|
||||||
return {
|
return {
|
||||||
...listCommunities,
|
...listCommunities,
|
||||||
@@ -293,7 +270,7 @@ export function fromListCommunities(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function fromCreateComment(
|
export function fromCreateComment(
|
||||||
createComment: CreateComment,
|
createComment: base.CreateComment,
|
||||||
): components['schemas']['CreateComment'] {
|
): components['schemas']['CreateComment'] {
|
||||||
return {
|
return {
|
||||||
...createComment,
|
...createComment,
|
||||||
@@ -303,7 +280,7 @@ export function fromCreateComment(
|
|||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
export function toSortType(
|
export function toSortType(
|
||||||
sortType?: SortType,
|
sortType?: base.SortType,
|
||||||
): components['schemas']['SortType'] | undefined {
|
): components['schemas']['SortType'] | undefined {
|
||||||
if (
|
if (
|
||||||
sortType == 'Old' ||
|
sortType == 'Old' ||
|
||||||
@@ -316,14 +293,14 @@ export function toSortType(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function toCommentSortType(
|
export function toCommentSortType(
|
||||||
commentSortType?: CommentSortType,
|
commentSortType?: base.CommentSortType,
|
||||||
): components['schemas']['CommentSortType'] | undefined {
|
): components['schemas']['CommentSortType'] | undefined {
|
||||||
if (commentSortType == 'Controversial') commentSortType = undefined
|
if (commentSortType == 'Controversial') commentSortType = undefined
|
||||||
return commentSortType
|
return commentSortType
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toCommunitiesSortType(
|
export function toCommunitiesSortType(
|
||||||
sortType?: SortType,
|
sortType?: base.SortType,
|
||||||
): 'Top' | 'Hot' | 'New' | undefined {
|
): 'Top' | 'Hot' | 'New' | undefined {
|
||||||
if (sortType == 'Hot' || sortType == 'New' || sortType == undefined)
|
if (sortType == 'Hot' || sortType == 'New' || sortType == undefined)
|
||||||
return sortType
|
return sortType
|
||||||
|
|||||||
Vendored
+2
-2
@@ -5809,7 +5809,7 @@ export interface components {
|
|||||||
note: string
|
note: string
|
||||||
}
|
}
|
||||||
UserSetNoteResponse: {
|
UserSetNoteResponse: {
|
||||||
person_view?: components['schemas']['PersonView']
|
person_view: components['schemas']['PersonView']
|
||||||
}
|
}
|
||||||
ListCommentsResponse: {
|
ListCommentsResponse: {
|
||||||
comments: components['schemas']['CommentView'][]
|
comments: components['schemas']['CommentView'][]
|
||||||
@@ -5873,7 +5873,7 @@ export interface components {
|
|||||||
id: number
|
id: number
|
||||||
creator_id: number
|
creator_id: number
|
||||||
comment_id: number
|
comment_id: number
|
||||||
original_comment_text?: string
|
original_comment_text: string
|
||||||
reason?: string
|
reason?: string
|
||||||
resolved: boolean
|
resolved: boolean
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user