![New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions](https://cdn.sanity.io/images/cgdhsj6q/production/86e6ebdea652d20da070ebbda20134b839972db7-1024x1024.webp?w=800&fit=max&auto=format)
Security News
New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
@jsheaven/astro-client-generator
Advanced tools
Readme
Generates TypeScript API client code for your Astro endpoints. No manual
fetch()
code writing anymore.
As an Astro developer, I don't want to write the fetch()
code for my Astro endpoints manually
As an Astro developer, I want type-safety and auto-complete in my IDE when calling my Astro endpoints.
get
, post
, del
, all
, etc.)fetch
under the hood, therefore works isomorphic in browser and in SSR/SSGnaive
(highly optimized) and baseline
(deoptimization, safer)2.64 kb
nano sized library0 byte
runtime overhead/dependencies as it just generates vanilla TS/JS codeIf you want to test it, simply run this command in your Astro project root folder:
npx @jsheaven/astro-client-generator generate
You need at least version 18 of Node.js installed.
yarn add @jsheaven/astro-client-generator
npm install @jsheaven/astro-client-generator
Add the following code to your astro.config.(js|ts)
:
import { apiClientGenerator } from '@jsheaven/astro-client-generator'
// https://astro.build/config
export default defineConfig({
...
integrations: [
// generate client API code for the endpoints
apiClientGenerator(),
]
})
You can enhance and customize this configuration:
import { apiClientGenerator } from '@jsheaven/astro-client-generator'
// https://astro.build/config
export default defineConfig({
...
integrations: [
apiClientGenerator({
// == all settings displayed here are optional. What you see here, are default values ==
/** folder to the API directory on disk (source code) */
root: './src/pages/api',
/** API base URL for calling the API (only relevant if you host in a subdir, it's unlikely) */
baseUrl: '',
/** folder on disk to write the client code to */
outDir: './src/pages/api-client',
/** parser to use. 'naive' comes with constraints (non-standard-compliant), 'baseline' is 900x slower */
parser: 'naive',
/** path to your tsconfig.json, from the root folder of your project */
tsConfigPath: './tsconfig.json',
}),
]
})
import { generateClientApis } from '@jsheaven/astro-client-generator'
const result = await generateClientApis({
// all optional, these are just the default values
root: './src/pages/api',
baseUrl: '',
outDir: './src/pages/api-client',
parser: 'naive',
tsConfigPath: './tsconfig.json',
})
const { generateClientApis } = require('@jsheaven/astro-client-generator')
// same API like ESM variant
The naive
parser in this package is a hand-written, highly optimized parser that is
capable of handling a subset of the official TypeScript / JavaScript syntax.
In naive
parsing mode, code generation will happen in 2 to 5ms
per endpoint,
file in baseline
mode, you can espect at least 1 sec
per endpoint. This is,
why naive
parsing is the default configuration.
If you follow the following rules, the naive
parser should be just working fine:
import
statements in a single linetype
definitions in a single line{
and }
inside of comments in interface
definitionsexport const get = ( ... ) => { ... }
async function get ( ... ) { ... }
get
, post
, del
, etc. that Astro supports, is supported), but keep the method name lowercaseHowever, if you're running into errors, please use the baseline
parser:
import { apiClientGenerator } from '@jsheaven/astro-client-generator'
// https://astro.build/config
export default defineConfig({
...
integrations: [
apiClientGenerator({
...
parser: 'baseline',
...
}),
]
})
Please take a look at the test fixtures to get an idea about what syntax is definitely supported. It should cover most of the simple and advanced use-cases.
FAQs
Generates TypeScript API client code for your Astro endpoints. No manual `fetch()` code writing anymore.
The npm package @jsheaven/astro-client-generator receives a total of 8 weekly downloads. As such, @jsheaven/astro-client-generator popularity was classified as not popular.
We found that @jsheaven/astro-client-generator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
Security News
Results from the 2023 State of JavaScript Survey highlight key trends, including Vite's dominance, rising TypeScript adoption, and the enduring popularity of React. Discover more insights on developer preferences and technology usage.
Security News
The US Justice Department has penalized two consulting firms $11.3 million for failing to meet cybersecurity requirements on federally funded projects, emphasizing strict enforcement to protect sensitive government data.