First attempt at TS_RS

This commit is contained in:
Natty 2023-11-03 13:17:53 +01:00
parent 5a8dc04915
commit 2c3d675392
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
65 changed files with 473 additions and 3 deletions

View File

@ -1,2 +1,6 @@
[registries.crates-io]
protocol = "sparse"
protocol = "sparse"
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"]

View File

@ -0,0 +1,112 @@
import {FrontendApiEndpoint, FrontendApiEndpoints} from "./fe-api";
import {GetNoteById} from "./types/endpoints/GetNoteById";
type Method = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
export interface BackendApiEndpoint<M extends Method, T, R> {
method: M;
endpoint: string;
pathParams: [string],
request?: T;
response?: R;
}
function nestedUrlSearchParams(data: any, topLevel: boolean = true): string {
switch (typeof data) {
case "string":
case "bigint":
case "boolean":
case "number":
case "symbol":
if (topLevel)
return encodeURIComponent(data.toString()) + "=";
return data.toString();
case "object":
if (data === null)
return "null";
if (Array.isArray(data))
return data.map(d => nestedUrlSearchParams(d, true))
.map(encodeURIComponent)
.join("&");
const inner = Object.entries(data)
.map(([k, v]) => [k, nestedUrlSearchParams(v, false)]);
return new URLSearchParams(inner).toString();
default:
return "";
}
}
type MagApiErrorCode = "Client:GenericApiError" | string;
export interface MagApiError {
status: number;
code: MagApiErrorCode,
message: string,
}
export class MagApiClient {
private readonly baseUrl: string;
constructor(baseUrl: string) {
this.baseUrl = baseUrl;
}
async call<M extends Method, T extends BackendApiEndpoint<M, T["request"], T["response"]>>(
endpoint: T["endpoint"],
method: M,
data: T["request"],
pathParams: Record<string, string>,
token?: string | null | undefined
): Promise<T["response"]> {
type Response = T["response"];
const authorizationToken = token ?? undefined;
const authorization = authorizationToken
? `Bearer ${authorizationToken}`
: undefined;
let url = `${this.baseUrl}/${endpoint}`;
if (method === "GET") {
const query = nestedUrlSearchParams(data as any);
if (query) {
url += `?${query}`;
}
}
return await fetch(url, {
method,
body: method !== "GET" ? JSON.stringify(data) : undefined,
credentials: "omit",
cache: "no-cache",
headers: authorization ? {authorization} : {},
})
.then(async (res) => {
const body = res.status === 204 ? null : await res.json();
if (res.status === 200) {
return body as Response;
} else if (res.status === 204) {
return null as any as Response;
} else {
throw body as MagApiError;
}
})
.catch((e) => {
throw ({
status: -1,
code: "Client:GenericApiError",
message: e
}) as MagApiError;
});
}
}
const a = new MagApiClient("https://aaa");
a.call<"GET", GetNoteById>("", "",{}, {})

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type AvatarDecoration = "None" | "CatEars";

View File

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ImageMeta } from "./ImageMeta";
export interface DriveFileBase { name: string, created_at: string, size: bigint, hash: string | null, mime_type: string, media_metadata: ImageMeta, url: string | null, thumbnail_url: string | null, sensitive: boolean, comment: string | null, folder_id: string | null, user_id: string | null, }

View File

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PackDriveFolderBase } from "./packed/PackDriveFolderBase";
export interface DriveFileFolderExt { folder: PackDriveFolderBase, }

View File

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PackUserBase } from "./packed/PackUserBase";
export interface DriveFileUserExt { user: PackUserBase, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface DriveFolderBase { name: string, created_at: string, comment: string | null, file_count: bigint, folder_count: bigint, parent_id: string | null, user_id: string, }

View File

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { DriveFolderBase } from "./DriveFolderBase";
export interface DriveFolderParentExt { folder: DriveFolderBase, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface EmojiBase { shortcode: string, url: string, category: string | null, width: number | null, height: number | null, }

View File

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PackEmojiBase } from "./packed/PackEmojiBase";
export type EmojiContext = Array<PackEmojiBase>;

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type FollowVisibility = "Public" | "Followers" | "Private";

View File

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { NoteListFilter } from "./NoteListFilter";
export interface GetTimelineReq { limit: bigint, filter: NoteListFilter | null, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface Id { id: string, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface ImageMeta { width: bigint | null, height: bigint | null, orientation: bigint | null, color: string | null, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type MmXml = string;

View File

@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PackDriveFileBase } from "./packed/PackDriveFileBase";
import type { PackPollBase } from "./packed/PackPollBase";
export interface NoteAttachmentExt { poll: PackPollBase | null, attachments: Array<PackDriveFileBase>, }

View File

@ -0,0 +1,8 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { EmojiContext } from "./EmojiContext";
import type { MmXml } from "./MmXml";
import type { NoteVisibility } from "./NoteVisibility";
import type { PackUserBase } from "./packed/PackUserBase";
import type { ReactionPair } from "./ReactionPair";
export interface NoteBase { created_at: string, cw: string | null, cw_mm: MmXml | null, uri: string | null, url: string | null, text: string, text_mm: MmXml | null, visibility: NoteVisibility, user: PackUserBase, parent_note_id: string | null, renoted_note_id: string | null, reply_count: bigint, renote_count: bigint, mentions: Array<string>, hashtags: Array<string>, reactions: Array<ReactionPair>, local_only: boolean, has_poll: boolean, file_ids: Array<string>, emojis: EmojiContext, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface NoteByIdReq { context: boolean, attachments: boolean, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface NoteListFilter { show_renotes: boolean | null, show_replies: boolean | null, show_files_only: boolean | null, uncwed_sensitive: boolean | null, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface NoteSelfContextExt { self_renote_count: bigint | null, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type NoteVisibility = "Public" | "Home" | "Followers" | "Direct";

View File

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { NotificationType } from "./NotificationType";
export interface NotificationSettings { enabled: Array<NotificationType>, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type NotificationType = "Follow" | "Mention" | "Reply" | "Renote" | "Quote" | "Reaction" | "PollVote" | "PollEnded" | "FollowRequest" | "FollowRequestAccepted" | "App";

View File

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PollChoice } from "./PollChoice";
export interface PollBase { expires_at: string | null, expired: boolean, multiple_choice: boolean, options: Array<PollChoice>, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface PollChoice { title: string, votes_count: bigint, voted: boolean | null, }

View File

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { MmXml } from "./MmXml";
export interface ProfileField { name: string, value: string, value_mm: MmXml | null, verified_at: string | null, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type Reaction = string | { name: string, host: string | null, url: string, } | { raw: string, };

View File

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Reaction } from "./Reaction";
export type ReactionPair = [Reaction, bigint] | [Reaction, bigint, boolean];

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface SecurityKeyBase { name: string, last_used_at: string | null, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type SpeechTransform = "None" | "Cat";

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface UserAuthOverviewExt { has_two_factor_enabled: boolean, has_passwordless_login: boolean, has_security_keys: boolean, }

View File

@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { AvatarDecoration } from "./AvatarDecoration";
import type { EmojiContext } from "./EmojiContext";
import type { MmXml } from "./MmXml";
import type { SpeechTransform } from "./SpeechTransform";
export interface UserBase { acct: string, username: string, display_name: string, display_name_mm: MmXml | null, host: string | null, speech_transform: SpeechTransform, created_at: string, avatar_url: string | null, avatar_blurhash: string | null, avatar_color: string | null, avatar_decoration: AvatarDecoration, is_admin: boolean, is_moderator: boolean, is_bot: boolean, emojis: EmojiContext, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface UserByIdReq { profile: boolean, pins: boolean, detail: boolean, relation: boolean, auth: boolean, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface UserDetailExt { last_fetched_at: string | null, uri: string | null, updated_at: string | null, }

View File

@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { MmXml } from "./MmXml";
import type { ProfileField } from "./ProfileField";
export interface UserProfileExt { is_locked: boolean, is_silenced: boolean, is_suspended: boolean, description: string | null, description_mm: MmXml | null, location: string | null, birthday: string | null, fields: Array<ProfileField>, follower_count: bigint | null, following_count: bigint | null, note_count: bigint | null, url: string | null, moved_to_uri: string | null, also_known_as: string | null, banner_url: string | null, banner_color: string | null, banner_blurhash: string | null, has_public_reactions: boolean, }

View File

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PackNoteMaybeFull } from "./packed/PackNoteMaybeFull";
export interface UserProfilePinsEx { pinned_notes: Array<PackNoteMaybeFull>, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface UserRelationExt { follows_you: boolean, you_follow: boolean, blocks_you: boolean, you_block: boolean, mute: boolean, mute_renotes: boolean, }

View File

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PackSecurityKeyBase } from "./packed/PackSecurityKeyBase";
export interface UserSecretsExt { email: string | null, email_verified: boolean, security_keys: Array<PackSecurityKeyBase>, }

View File

@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { NotificationSettings } from "./NotificationSettings";
export interface UserSelfExt { avatar_id: string | null, banner_id: string | null, email_announcements: boolean, always_mark_sensitive: boolean, reject_bot_follow_requests: boolean, reject_crawlers: boolean, reject_ai_training: boolean, has_unread_announcements: boolean, has_unread_antenna: boolean, has_unread_notifications: boolean, has_pending_follow_requests: boolean, word_mutes: Array<string>, instance_mutes: Array<string>, notification_settings: NotificationSettings, }

View File

@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export interface UserSelfReq { profile: boolean, pins: boolean, detail: boolean, secrets: boolean, }

View File

@ -0,0 +1,11 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { NoteByIdReq } from "../NoteByIdReq";
import type { PackNoteMaybeFull } from "../packed/PackNoteMaybeFull";
interface GetNoteById {
endpoint: "/notes/:id",
pathParams: ["id"],
method: "GET",
request: NoteByIdReq,
response: PackNoteMaybeFull
}

View File

@ -0,0 +1,12 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { GetTimelineReq } from "../GetTimelineReq";
import type { PackNoteMaybeFull } from "../packed/PackNoteMaybeFull";
export interface GetTimeline {
endpoint: "/timeline";
pathParams: [];
method: "GET";
request: GetTimelineReq;
response: Array<PackNoteMaybeFull>;
}

View File

@ -0,0 +1,12 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PackUserMaybeAll } from "../packed/PackUserMaybeAll";
import type { UserByIdReq } from "../UserByIdReq";
export interface GetUserByAcct {
endpoint: "/users/by-acct/:user_id";
pathParams: ["user_id"];
method: "GET";
request: UserByIdReq;
response: PackUserMaybeAll;
}

View File

@ -0,0 +1,12 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PackUserMaybeAll } from "../packed/PackUserMaybeAll";
import type { UserByIdReq } from "../UserByIdReq";
export interface GetUserById {
endpoint: "/users/:user_id";
pathParams: ["user_id"];
method: "GET";
request: UserByIdReq;
response: PackUserMaybeAll;
}

View File

@ -0,0 +1,12 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PackUserSelfMaybeAll } from "../packed/PackUserSelfMaybeAll";
import type { UserSelfReq } from "../UserSelfReq";
export interface GetUserSelf {
endpoint: "/users/@self";
pathParams: [];
method: "GET";
request: UserSelfReq;
response: PackUserSelfMaybeAll;
}

View File

@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { DriveFileBase } from "../DriveFileBase";
import type { Id } from "../Id";
export type PackDriveFileBase = Id & DriveFileBase;

View File

@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { DriveFileBase } from "../DriveFileBase";
import type { DriveFileFolderExt } from "../DriveFileFolderExt";
import type { DriveFileUserExt } from "../DriveFileUserExt";
import type { Id } from "../Id";
export type PackDriveFileFull = Id & DriveFileBase & DriveFileFolderExt & DriveFileUserExt;

View File

@ -0,0 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { DriveFileBase } from "../DriveFileBase";
import type { DriveFileFolderExt } from "../DriveFileFolderExt";
import type { Id } from "../Id";
export type PackDriveFileWithFolder = Id & DriveFileBase & DriveFileFolderExt;

View File

@ -0,0 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { DriveFileBase } from "../DriveFileBase";
import type { DriveFileUserExt } from "../DriveFileUserExt";
import type { Id } from "../Id";
export type PackDriveFileWithUser = Id & DriveFileBase & DriveFileUserExt;

View File

@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { DriveFolderBase } from "../DriveFolderBase";
import type { Id } from "../Id";
export type PackDriveFolderBase = Id & DriveFolderBase;

View File

@ -0,0 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { DriveFolderBase } from "../DriveFolderBase";
import type { DriveFolderParentExt } from "../DriveFolderParentExt";
import type { Id } from "../Id";
export type PackDriveFolderWithParent = Id & DriveFolderBase & DriveFolderParentExt;

View File

@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { EmojiBase } from "../EmojiBase";
import type { Id } from "../Id";
export type PackEmojiBase = Id & EmojiBase;

View File

@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Id } from "../Id";
import type { NoteBase } from "../NoteBase";
export type PackNoteBase = Id & NoteBase;

View File

@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Id } from "../Id";
import type { NoteAttachmentExt } from "../NoteAttachmentExt";
import type { NoteBase } from "../NoteBase";
import type { NoteSelfContextExt } from "../NoteSelfContextExt";
export type PackNoteMaybeAttachments = Id & NoteBase & Partial<NoteSelfContextExt> & Partial<NoteAttachmentExt>;

View File

@ -0,0 +1,8 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Id } from "../Id";
import type { NoteAttachmentExt } from "../NoteAttachmentExt";
import type { NoteBase } from "../NoteBase";
import type { NoteDetailExt } from "../NoteDetailExt";
import type { NoteSelfContextExt } from "../NoteSelfContextExt";
export type PackNoteMaybeFull = Id & NoteBase & Partial<NoteSelfContextExt> & Partial<NoteAttachmentExt> & Partial<NoteDetailExt>;

View File

@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Id } from "../Id";
import type { PollBase } from "../PollBase";
export type PackPollBase = Id & PollBase;

View File

@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Id } from "../Id";
import type { SecurityKeyBase } from "../SecurityKeyBase";
export type PackSecurityKeyBase = Id & SecurityKeyBase;

View File

@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Id } from "../Id";
import type { UserBase } from "../UserBase";
export type PackUserBase = Id & UserBase;

View File

@ -0,0 +1,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Id } from "../Id";
import type { UserAuthOverviewExt } from "../UserAuthOverviewExt";
import type { UserBase } from "../UserBase";
import type { UserDetailExt } from "../UserDetailExt";
import type { UserProfileExt } from "../UserProfileExt";
import type { UserProfilePinsEx } from "../UserProfilePinsEx";
import type { UserRelationExt } from "../UserRelationExt";
export type PackUserMaybeAll = Id & UserBase & Partial<UserProfileExt> & Partial<UserProfilePinsEx> & Partial<UserDetailExt> & Partial<UserRelationExt> & Partial<UserAuthOverviewExt>;

View File

@ -0,0 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Id } from "../Id";
import type { UserBase } from "../UserBase";
import type { UserSelfExt } from "../UserSelfExt";
export type PackUserSelf = Id & UserBase & UserSelfExt;

View File

@ -0,0 +1,9 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Id } from "../Id";
import type { UserBase } from "../UserBase";
import type { UserDetailExt } from "../UserDetailExt";
import type { UserProfileExt } from "../UserProfileExt";
import type { UserProfilePinsEx } from "../UserProfilePinsEx";
import type { UserSecretsExt } from "../UserSecretsExt";
export type PackUserSelfMaybeAll = Id & UserBase & Partial<UserProfileExt> & Partial<UserProfilePinsEx> & Partial<UserDetailExt> & Partial<UserSecretsExt>;

View File

@ -9,8 +9,9 @@
"packageManager": "pnpm@8.6.3",
"private": true,
"scripts": {
"rebuild": "pnpm run clean && pnpm -r run build && pnpm run gulp",
"build": "pnpm -r run build && pnpm run gulp",
"magnetar-types": "pnpm node ./scripts/magnetar-types.js",
"rebuild": "pnpm run clean && pnpm run magnetar-types && pnpm -r run build && pnpm run gulp",
"build": "pnpm run magnetar-types && pnpm -r run build && pnpm run gulp",
"gulp": "gulp build",
"dev:staging": "NODE_OPTIONS=--max_old_space_size=3072 NODE_ENV=development pnpm run build && pnpm run start",
"lint": "pnpm -r run lint",

View File

@ -0,0 +1,33 @@
const fs = require("node:fs");
const execa = require("execa");
const chalk = require("chalk");
const { join } = require("node:path");
(async () => {
console.log(chalk.italic`Generating Magnetar types, this may take a while...`)
const { failed } = await execa.command("cargo test --release --package magnetar_sdk", {
cwd: "../../magnetar_sdk",
stdout: "inherit"
});
if (failed) {
console.error(chalk.red`Type generation failed.`);
return;
}
console.log(chalk.green`Successfully generated Magnetar types`);
const srcPath = "../../magnetar_sdk/bindings";
const destPath = "magnetar-common/src/types";
console.log(chalk.italic`Deleting old`, `"${destPath}"`);
fs.rmSync(destPath, { recursive: true, force: true });
console.log(chalk.italic`Copying generated Magnetar types...`);
console.log(chalk.italic`From`, `"${srcPath}"`, chalk.italic`to`, `"${destPath}"`);
fs.cpSync(`${srcPath}/`, `${destPath}/`, { recursive: true });
console.log(chalk.italic`Deleting`, `"${srcPath}"`);
fs.rmSync(srcPath, { recursive: true, force: true });
})();

View File

@ -272,6 +272,24 @@ pub fn derive_endpoint(item: TokenStream) -> TokenStream {
let request = request.expect("missing request attribute");
let response = response.expect("missing response attribute");
let mut endpoint_chars = endpoint.chars();
let mut path_params = String::from("[");
while let Some(c) = endpoint_chars.next() {
if c == ':' {
if !path_params.ends_with('[') {
path_params += ", ";
}
path_params += "\"";
path_params += &endpoint_chars
.clone()
.take_while(|c| c.is_ascii_alphanumeric() || *c == '_')
.collect::<String>();
path_params += "\"";
}
}
path_params += "]";
let ts_path = format!("bindings/endpoints/{}.ts", name);
let export_name = Ident::new(
&format!("export_bindings_{}", struct_name.to_string().to_lowercase()),
@ -340,6 +358,7 @@ pub fn derive_endpoint(item: TokenStream) -> TokenStream {
format!(
"interface {} {{\n \
endpoint: \"{}\";\n \
pathParams: {};\n \
method: \"{}\";\n \
request: {};\n \
response: {};\n\
@ -347,6 +366,7 @@ pub fn derive_endpoint(item: TokenStream) -> TokenStream {
",
Self::name(),
Self::ENDPOINT,
#path_params,
Self::METHOD,
#call_name_req,
#call_name_res

View File

@ -93,6 +93,7 @@ pack!(
);
#[derive(Clone, Debug, Deserialize, Serialize, TS)]
#[ts(export)]
pub struct NoteDetailExt {
pub parent_note: Option<Box<PackNoteMaybeAttachments>>,
pub renoted_note: Option<Box<PackNoteMaybeAttachments>>,