An automated tool help you to transform backend json data to TypeScript type.

Overview

ohmyts

An automated tool help you to transform backend json data to TypeScript type.

Quick Start

Vite

install

npm i @ohmyts/vite -D

🤽 playground

playground

usage

vite.config.ts

import { ohmytsVite } from '@ohmyts/vite'

const r = (p: string) => resolve(__dirname, p)

export default defineConfig({
  plugins: [
    ohmytsVite({
      target: '/api',
      rootDir: r('@types'),
      proxyOptions: {
        target: 'https://autumnfish.cn',
      },
    }),
  ]
})

app.tsx for more detail, please go playground to check

import axios from 'axios'
import { defineComponent } from 'vue'

const App = defineComponent(() => {
  const { data } = useQuery(() => axios.get('/api/search?keywords=MELANCHOLY'))

  return () => (
    // ...
  )
})

for example, if the backend return as below

{
  "data": 1
}

it will create @types/GET_Search.d.ts as below

declare interface IGetSearchResponseType {
  data: number
}

File naming rule

${options.rootDir}/${req.Method}_${pathname(req.url)}

what is pathname function? for example

pathname('/api/search?keywords=hello') === 'ApiSearch'

Type naming rule

the rule of type name is I${pathname(req.Method)}${pathname(req.url)}${options.suffix}

Type

import type { Plugin } from 'vite'

declare function ohmytsVite(options: OhmytsOptions | OhmytsOptions[]): Plugin

Options

import type { ServerOptions } from 'http-proxy'

export interface OhmytsOptions {
  /*
  * rewrite url
  */
  target: string
  /*
  * proxy server options
  *
  */
  proxyOptions: ServerOptions
  /*
  * the root dir path generate type file
  *
  * @default '@types/'
  */
  rootDir?: string
  /*
  * encoding
  *
  * @default 'utf-8'
  */
  encoding?: BufferEncoding
  /*
  * the suffix of generated root type
  *
  * @default 'ResponseType'
  */
  suffix?: string
  /*
  * should overwrite in next time
  *
  * @default true
  */
  overwrite?: boolean
  /*
  * use `declare` to decorate type or it will be `export`
  *
  * @default true
  */
  declare?: boolean
}
You might also like...

Combine type and value imports using Typescript 4.5 type modifier syntax

type-import-codemod Combines your type and value imports together into a single statement, using Typescript 4.5's type modifier syntax. Before: import

Sep 29, 2022

A type programming language which compiles to and interops with type-level TypeScript

Prakaar Prakaar (hindi for "type") is a type programming language which compiles to and interops with type-level TypeScript. Prakaar itself is also a

Sep 21, 2022

A type speed checking website which lets you check your typing speed and shows the real-tme leaderboards with mongodb as DB and express as backend

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Mar 27, 2022

Transform and compose data for HTTP transactions.

Transform and compose data for HTTP transactions.

Fragments Fragments is a platform to compose and manage custom data objects for HTTP transactions. Simply put, you can write simple jinja templates to

Sep 6, 2022

A typescript transform that converts exported const enums into object literal.

ts-transformer-optimize-const-enum A typescript transformer that convert exported const enum into object literal. This is just like the one from @babe

Jul 27, 2022

Gatsby-Formik-contact-form-with-backend-panel - Full working contact form with backend GUI panel.

Gatsby minimal starter 🚀 Quick start Create a Gatsby site. Use the Gatsby CLI to create a new site, specifying the minimal starter. # create a new Ga

Jan 2, 2022

Venni backend - The backend of the Venni client apps implementing the credit card payments, matching algorithms, bank transfers, trip rating system, and more.

Cloud Functions Description This repository contains the cloud functions used in the Firebase backend of the Venni apps. Local Development Setup For t

Jan 3, 2022

The JavaScript library let’s you transform native tooltip’s into customizable overlays.

iTooltip The JavaScript library let’s you transform native tooltip’s into customizable overlays. Use: script src="/path/to/iTooltip.js"/script sc

Dec 17, 2021

Type predicate functions for checking if a value is of a specific type or asserting that it is.

As-Is Description As-Is contains two modules. Is - Type predicates for checking values are of certain types. As - Asserting values are of a certain ty

Feb 10, 2022
Comments
  • Configure Renovate

    Configure Renovate

    Mend Renovate

    Welcome to Renovate! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.


    Detected Package Files

    • package.json (npm)
    • packages/playground/package.json (npm)
    • packages/shared/package.json (npm)
    • packages/vite/package.json (npm)

    Configuration

    🔡 Renovate has detected a custom config for this PR. Feel free to ask for help if you have any doubts and would like it reviewed.

    Important: Now that this branch is edited, Renovate can't rebase it from the base branch any more. If you make changes to the base branch that could impact this onboarding PR, please merge them manually.

    What to Expect

    With your current configuration, Renovate will create 11 Pull Requests:

    chore(deps): update dependency @​antfu/eslint-config to ^0.31.0
    • Schedule: ["at any time"]
    • Branch name: renovate/antfu-eslint-config-0.x
    • Merge into: master
    • Upgrade @antfu/eslint-config to ^0.31.0
    chore(deps): update dependency @​antfu/ni to ^0.18.0
    • Schedule: ["at any time"]
    • Branch name: renovate/antfu-ni-0.x
    • Merge into: master
    • Upgrade @antfu/ni to ^0.18.0
    chore(deps): update dependency eslint to v8.28.0
    • Schedule: ["at any time"]
    • Branch name: renovate/eslint-8.x
    • Merge into: master
    • Upgrade eslint to 8.28.0
    chore(deps): update dependency unbuild to ^0.9.0
    • Schedule: ["at any time"]
    • Branch name: renovate/unbuild-0.x
    • Merge into: master
    • Upgrade unbuild to ^0.9.0
    chore(deps): update dependency vite to v3.2.4
    • Schedule: ["at any time"]
    • Branch name: renovate/vite-3.x
    • Merge into: master
    • Upgrade vite to 3.2.4
    chore(deps): update dependency vitest to ^0.25.0
    • Schedule: ["at any time"]
    • Branch name: renovate/vitest-monorepo
    • Merge into: master
    • Upgrade vitest to ^0.25.0
    chore(deps): update dependency gzip-size to v7
    • Schedule: ["at any time"]
    • Branch name: renovate/gzip-size-7.x
    • Merge into: master
    • Upgrade gzip-size to ^7.0.0
    chore(deps): update dependency rollup to v3
    • Schedule: ["at any time"]
    • Branch name: renovate/rollup-3.x
    • Merge into: master
    • Upgrade rollup to ^3.0.0
    chore(deps): update dependency unbuild to v1
    • Schedule: ["at any time"]
    • Branch name: renovate/unbuild-1.x
    • Merge into: master
    • Upgrade unbuild to ^1.0.0
    chore(deps): update dependency vue-tsc to v1
    • Schedule: ["at any time"]
    • Branch name: renovate/vue-tsc-1.x
    • Merge into: master
    • Upgrade vue-tsc to ^1.0.0
    fix(deps): update dependency axios to v1
    • Schedule: ["at any time"]
    • Branch name: renovate/axios-1.x
    • Merge into: master
    • Upgrade axios to ^1.0.0

    🚸 Branch creation will be limited to maximum 2 per hour, so it doesn't swamp any CI resources or spam the project. See docs for prhourlylimit for details.


    ❓ Got questions? Check out Renovate's Docs, particularly the Getting Started section. If you need any further assistance then you can also request help here.


    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
Releases(v0.0.8)
Owner
snowingfox
snowingfox
A transpiler from golang's type to typescript's type for collaboration between frontend & backend.

go2type go2type.vercel.app (backup site) A typescript transpiler that convert golang's type to typescript's type. Help front-end developer to work fas

Oanakiaja 8 Sep 26, 2022
a vscode extension for http response data auto transform ts type.

Api2ts 这是一个自动将 http 的响应数据转化为 ts 的类型,使用 json-to-ts 做的。 Features 框选配置项后,使用快捷键 alt+Q : 请求参数配置文件 在根目录下创建 Api2ts.config.json 文件,配置项如下: { "baseURL": "http

phy-lei 6 Jun 30, 2022
Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator Types generator is a utility tool that will help User to create TS Interfaces from JSON. All you have to do is paste your single objec

Vineeth.TR 16 Dec 6, 2022
🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

?? HypeScript Introduction This is a simplified implementation of TypeScript's type system that's written in TypeScript's type annotations. This means

Ronen Amiel 1.8k Dec 20, 2022
e-ONG, an authorial project, whose objective is to help ONGs to find people who need help or would like to help them

This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: npm start Runs the app in the developmen

Lucas Lima 2 Nov 11, 2022
✏️ A small jQuery extension to turn a static HTML table into an editable one. For quickly populating a small table with JSON data, letting the user modify it with validation, and then getting JSON data back out.

jquery-editable-table A small jQuery extension to turn an HTML table editable for fast data entry and validation Demo ?? https://jsfiddle.net/torrobin

Tor 7 Jul 31, 2022
Pretty-print-json - 🦋 Pretty-print JSON data into HTML to indent and colorize (written in TypeScript)

pretty-print-json Pretty-print JSON data into HTML to indent and colorize (written in TypeScript) 1) Try It Out Interactive online tool to format JSON

Center Key 87 Dec 30, 2022
JCS (JSON Canonicalization Scheme), JSON digests, and JSON Merkle hashes

JSON Hash This package contains the following JSON utilties for Deno: digest.ts provides cryptographic hash digests of JSON trees. It guarantee that d

Hong Minhee (洪 民憙) 13 Sep 2, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
Purple hats Desktop is a customisable, automated web accessibility testing tool that allows software development teams to find and fix accessibility problems to improve persons with disabilities (PWDs) access to digital services.

Purple HATS Desktop Purple hats Desktop is a desktop frontend for Purple HATS accessibility site scanner - a customisable, automated web accessibility

Government Digital Services, Singapore 6 May 11, 2023