@jsheaven/astro-client-generator
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -51,3 +51,4 @@ #!/usr/bin/env node | ||
outDir: "./src/pages/api-client", | ||
tsConfigPath: "./tsconfig.json" | ||
tsConfigPath: "./tsconfig.json", | ||
site: "http://localhost:3000" | ||
}; | ||
@@ -54,0 +55,0 @@ var AstroHttpEndpointMethodNames = ["GET", "POST", "DEL", "PATCH", "HEAD", "PUT", "OPTIONS", "ALL"]; |
@@ -16,3 +16,4 @@ #!/usr/bin/env node | ||
outDir: "./src/pages/api-client", | ||
tsConfigPath: "./tsconfig.json" | ||
tsConfigPath: "./tsconfig.json", | ||
site: "http://localhost:3000" | ||
}; | ||
@@ -19,0 +20,0 @@ var AstroHttpEndpointMethodNames = ["GET", "POST", "DEL", "PATCH", "HEAD", "PUT", "OPTIONS", "ALL"]; |
@@ -47,3 +47,4 @@ #!/usr/bin/env node | ||
outDir: "./src/pages/api-client", | ||
tsConfigPath: "./tsconfig.json" | ||
tsConfigPath: "./tsconfig.json", | ||
site: "http://localhost:3000" | ||
}; | ||
@@ -50,0 +51,0 @@ var AstroHttpEndpointMethodNames = ["GET", "POST", "DEL", "PATCH", "HEAD", "PUT", "OPTIONS", "ALL"]; |
@@ -13,2 +13,4 @@ import type { AstroIntegration } from 'astro'; | ||
parser?: 'naive' | 'baseline'; | ||
/** site URL to request from. Optional, usually auto-discovered from Astro config */ | ||
site?: string; | ||
} | ||
@@ -33,16 +35,2 @@ export declare const apiGeneratorOptionsDefaults: ApiClientGeneratorOptions; | ||
}; | ||
export interface ApiClientGeneratorOptions { | ||
/** folder to the API directory on disk (source code), default: './src/pages/api' */ | ||
apiDir?: string; | ||
/** API base URL for calling the API (only relevant if you host in a subdir, it's very unlikely), default: '' */ | ||
baseUrl?: string; | ||
/** folder on disk to write the client code to, default: './src/pages/api-client' */ | ||
outDir?: string; | ||
/** path to tsconfig.json, default: './tsconfig.json' as it is expected to run in project root */ | ||
tsConfigPath?: string; | ||
/** parser to use. 'naive' comes with constraints (non-standard-compliant), 'baseline' is 900x slower, default: 'naive' */ | ||
parser?: 'naive' | 'baseline'; | ||
/** site URL to request from. Optional, usually auto-discovered from Astro config */ | ||
site?: string; | ||
} | ||
/** Astro integration function to add to integrations [apiClientGenerator()] array in astro.config.js */ | ||
@@ -49,0 +37,0 @@ export declare const apiClientGenerator: (apiGeneratorOptions?: ApiClientGeneratorOptions) => AstroIntegration; |
@@ -58,3 +58,4 @@ var __create = Object.create; | ||
outDir: "./src/pages/api-client", | ||
tsConfigPath: "./tsconfig.json" | ||
tsConfigPath: "./tsconfig.json", | ||
site: "http://localhost:3000" | ||
}; | ||
@@ -103,5 +104,3 @@ var AstroHttpEndpointMethodNames = ["GET", "POST", "DEL", "PATCH", "HEAD", "PUT", "OPTIONS", "ALL"]; | ||
hooks: { | ||
"astro:config:setup": async ({ config }) => { | ||
if (!apiGeneratorOptions.site) | ||
apiGeneratorOptions.site = config.site; | ||
"astro:config:setup": async () => { | ||
generateClientApis(apiGeneratorOptions); | ||
@@ -108,0 +107,0 @@ } |
@@ -13,2 +13,4 @@ import type { AstroIntegration } from 'astro'; | ||
parser?: 'naive' | 'baseline'; | ||
/** site URL to request from. Optional, usually auto-discovered from Astro config */ | ||
site?: string; | ||
} | ||
@@ -33,16 +35,2 @@ export declare const apiGeneratorOptionsDefaults: ApiClientGeneratorOptions; | ||
}; | ||
export interface ApiClientGeneratorOptions { | ||
/** folder to the API directory on disk (source code), default: './src/pages/api' */ | ||
apiDir?: string; | ||
/** API base URL for calling the API (only relevant if you host in a subdir, it's very unlikely), default: '' */ | ||
baseUrl?: string; | ||
/** folder on disk to write the client code to, default: './src/pages/api-client' */ | ||
outDir?: string; | ||
/** path to tsconfig.json, default: './tsconfig.json' as it is expected to run in project root */ | ||
tsConfigPath?: string; | ||
/** parser to use. 'naive' comes with constraints (non-standard-compliant), 'baseline' is 900x slower, default: 'naive' */ | ||
parser?: 'naive' | 'baseline'; | ||
/** site URL to request from. Optional, usually auto-discovered from Astro config */ | ||
site?: string; | ||
} | ||
/** Astro integration function to add to integrations [apiClientGenerator()] array in astro.config.js */ | ||
@@ -49,0 +37,0 @@ export declare const apiClientGenerator: (apiGeneratorOptions?: ApiClientGeneratorOptions) => AstroIntegration; |
@@ -13,2 +13,4 @@ import type { AstroIntegration } from 'astro'; | ||
parser?: 'naive' | 'baseline'; | ||
/** site URL to request from. Optional, usually auto-discovered from Astro config */ | ||
site?: string; | ||
} | ||
@@ -33,16 +35,2 @@ export declare const apiGeneratorOptionsDefaults: ApiClientGeneratorOptions; | ||
}; | ||
export interface ApiClientGeneratorOptions { | ||
/** folder to the API directory on disk (source code), default: './src/pages/api' */ | ||
apiDir?: string; | ||
/** API base URL for calling the API (only relevant if you host in a subdir, it's very unlikely), default: '' */ | ||
baseUrl?: string; | ||
/** folder on disk to write the client code to, default: './src/pages/api-client' */ | ||
outDir?: string; | ||
/** path to tsconfig.json, default: './tsconfig.json' as it is expected to run in project root */ | ||
tsConfigPath?: string; | ||
/** parser to use. 'naive' comes with constraints (non-standard-compliant), 'baseline' is 900x slower, default: 'naive' */ | ||
parser?: 'naive' | 'baseline'; | ||
/** site URL to request from. Optional, usually auto-discovered from Astro config */ | ||
site?: string; | ||
} | ||
/** Astro integration function to add to integrations [apiClientGenerator()] array in astro.config.js */ | ||
@@ -49,0 +37,0 @@ export declare const apiClientGenerator: (apiGeneratorOptions?: ApiClientGeneratorOptions) => AstroIntegration; |
@@ -10,3 +10,4 @@ // src/index.ts | ||
outDir: "./src/pages/api-client", | ||
tsConfigPath: "./tsconfig.json" | ||
tsConfigPath: "./tsconfig.json", | ||
site: "http://localhost:3000" | ||
}; | ||
@@ -55,5 +56,3 @@ var AstroHttpEndpointMethodNames = ["GET", "POST", "DEL", "PATCH", "HEAD", "PUT", "OPTIONS", "ALL"]; | ||
hooks: { | ||
"astro:config:setup": async ({ config }) => { | ||
if (!apiGeneratorOptions.site) | ||
apiGeneratorOptions.site = config.site; | ||
"astro:config:setup": async () => { | ||
generateClientApis(apiGeneratorOptions); | ||
@@ -60,0 +59,0 @@ } |
@@ -13,2 +13,4 @@ import type { AstroIntegration } from 'astro'; | ||
parser?: 'naive' | 'baseline'; | ||
/** site URL to request from. Optional, usually auto-discovered from Astro config */ | ||
site?: string; | ||
} | ||
@@ -33,16 +35,2 @@ export declare const apiGeneratorOptionsDefaults: ApiClientGeneratorOptions; | ||
}; | ||
export interface ApiClientGeneratorOptions { | ||
/** folder to the API directory on disk (source code), default: './src/pages/api' */ | ||
apiDir?: string; | ||
/** API base URL for calling the API (only relevant if you host in a subdir, it's very unlikely), default: '' */ | ||
baseUrl?: string; | ||
/** folder on disk to write the client code to, default: './src/pages/api-client' */ | ||
outDir?: string; | ||
/** path to tsconfig.json, default: './tsconfig.json' as it is expected to run in project root */ | ||
tsConfigPath?: string; | ||
/** parser to use. 'naive' comes with constraints (non-standard-compliant), 'baseline' is 900x slower, default: 'naive' */ | ||
parser?: 'naive' | 'baseline'; | ||
/** site URL to request from. Optional, usually auto-discovered from Astro config */ | ||
site?: string; | ||
} | ||
/** Astro integration function to add to integrations [apiClientGenerator()] array in astro.config.js */ | ||
@@ -49,0 +37,0 @@ export declare const apiClientGenerator: (apiGeneratorOptions?: ApiClientGeneratorOptions) => AstroIntegration; |
@@ -41,3 +41,4 @@ (() => { | ||
outDir: "./src/pages/api-client", | ||
tsConfigPath: "./tsconfig.json" | ||
tsConfigPath: "./tsconfig.json", | ||
site: "http://localhost:3000" | ||
}; | ||
@@ -86,5 +87,3 @@ var AstroHttpEndpointMethodNames = ["GET", "POST", "DEL", "PATCH", "HEAD", "PUT", "OPTIONS", "ALL"]; | ||
hooks: { | ||
"astro:config:setup": async ({ config }) => { | ||
if (!apiGeneratorOptions.site) | ||
apiGeneratorOptions.site = config.site; | ||
"astro:config:setup": async () => { | ||
generateClientApis(apiGeneratorOptions); | ||
@@ -91,0 +90,0 @@ } |
{ | ||
"name": "@jsheaven/astro-client-generator", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -25,2 +25,5 @@ <h1 align="center">@jsheaven/astro-client-generator</h1> | ||
See [the TODO list example](example/todo-list/src/pages/index.astro). | ||
Example of the [generated API client code](example/todo-list/src/pages/api-client/). | ||
<h2 align="center">Example usage / test it (CLI)</h2> | ||
@@ -69,3 +72,4 @@ | ||
// == all settings displayed here are optional. What you see here, are default values == | ||
/** site URL to request from */ | ||
site: 'http://localhost:3000', | ||
/** folder to the API directory on disk (source code) */ | ||
@@ -140,7 +144,7 @@ apiDir: './src/pages/api', | ||
```ts | ||
import { userClientGet } from '../pages/client-api/user-client' | ||
import { getUser } from '../pages/client-api/user-client' | ||
// let's say we're using Cookie authentication (@jsheaven/astro-auth), | ||
// or no authentication -- so we don't have to do anything | ||
const user = await userClientGet() | ||
const user = await getUser() | ||
``` | ||
@@ -154,7 +158,7 @@ | ||
```ts | ||
import { userClientGet } from '../pages/client-api/user-client' | ||
import { getUser } from '../pages/client-api/user-client' | ||
import { getToken } from '@jsheaven/astro-oauth' | ||
// because the user GET endpoint has no body, the first argument is the fetch() options | ||
const user = await userClientGet({ | ||
const user = await getUser({ | ||
headers: { | ||
@@ -161,0 +165,0 @@ Authentication: `Bearer ${getToken()}`, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
262
278872
2747