Socket
Socket
Sign inDemoInstall

aspida

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aspida - npm Package Compare versions

Comparing version 0.19.4 to 0.20.0

dist/cli.d.ts

7

dist/buildTemplate.d.ts

@@ -1,8 +0,7 @@

import { BaseConfig } from './getConfig';
export declare type Template = {
import { AspidaConfig } from './getConfigs';
declare const _default: ({ input, baseURL, trailingSlash, outputEachDir }: AspidaConfig) => {
text: string;
filePath: string;
};
declare const _default: ({ input, baseURL, trailingSlash, outputEachDir }: BaseConfig) => Template[];
}[];
export default _default;
//# sourceMappingURL=buildTemplate.d.ts.map

@@ -8,3 +8,3 @@ "use strict";

var fs_1 = __importDefault(require("fs"));
var parseInterface_1 = __importDefault(require("./parseInterface"));
var parseInterface_1 = require("./parseInterface");
exports.getDirentTree = function (input) {

@@ -24,4 +24,4 @@ var tree = { path: input, children: [] };

else if (dirent.name.endsWith('.ts')) {
var methodsInterface = parseInterface_1.default(fs_1.default.readFileSync(input + "/" + dirent.name, 'utf8'), 'Methods');
if (!methodsInterface || methodsInterface.every(function (_a) {
var methods = parseInterface_1.parse(fs_1.default.readFileSync(input + "/" + dirent.name, 'utf8'), 'Methods');
if (!methods || methods.every(function (_a) {
var props = _a.props;

@@ -31,7 +31,3 @@ return !Object.keys(props).length;

return;
tree.children.push({
name: dirent.name,
isDir: false,
methods: methodsInterface
});
tree.children.push({ name: dirent.name, isDir: false, methods: methods });
}

@@ -38,0 +34,0 @@ });

@@ -11,4 +11,4 @@ import { LowerHttpMethod, AspidaMethodParams } from './';

};
declare const _default: (text: string, name: string) => Method[] | null;
export default _default;
export declare const parse: (text: string, name: string) => Method[] | null;
export {};
//# sourceMappingURL=parseInterface.d.ts.map

@@ -19,2 +19,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = void 0;
var quoteRegExp = /['"]/;

@@ -94,3 +95,3 @@ var openRegExp = /[(<{]/;

}
else if (/[^ \n;,]/.test(first)) {
else if (/[^ \r\n;,]/.test(first)) {
break;

@@ -205,3 +206,3 @@ }

};
exports.default = (function (text, name) {
exports.parse = function (text, name) {
var interfaceRegExp = new RegExp("(^|\n)export (interface " + name + "|type " + name + " ?=) ?{");

@@ -213,3 +214,3 @@ if (!interfaceRegExp.test(text))

return methods.length ? methods : null;
});
};
//# sourceMappingURL=parseInterface.js.map

@@ -1,4 +0,6 @@

import { Template } from './buildTemplate';
declare const _default: ({ filePath, text }: Template) => void;
declare const _default: ({ filePath, text }: {
filePath: string;
text: string;
}) => void;
export default _default;
//# sourceMappingURL=writeRouteFile.d.ts.map
{
"name": "aspida",
"version": "0.19.4",
"version": "0.20.0",
"description": "TypeScript friendly HTTP client wrapper for the browser and node.js",

@@ -9,9 +9,9 @@ "author": "Solufa <solufa2020@gmail.com>",

"bin": "bin/index.js",
"homepage": "https://github.com/aspidajs/aspida#readme",
"homepage": "https://github.com/aspida/aspida#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/aspidajs/aspida.git"
"url": "git+https://github.com/aspida/aspida.git"
},
"bugs": {
"url": "https://github.com/aspidajs/aspida/issues"
"url": "https://github.com/aspida/aspida/issues"
},

@@ -28,5 +28,5 @@ "files": [

"dependencies": {
"chokidar": "^3.4.0",
"chokidar": "^3.4.1",
"minimist": "^1.2.5"
}
}

@@ -11,3 +11,3 @@ | aspida | [aspida-mock] | [@aspida/axios] | [@aspida/ky] | [@aspida/fetch] | [@aspida/node-fetch] |

<div align="center">
<img src="https://aspidajs.github.io/aspida/logos/svg/black.svg" alt="aspida" title="aspida" width="600" />
<img src="https://aspida.github.io/aspida/logos/svg/black.svg" alt="aspida" title="aspida" width="600" />
</div>

@@ -21,15 +21,15 @@ <br />

</a>
<a href="https://github.com/aspidajs/aspida/actions?query=workflow%3A%22Node.js+CI%22">
<img src="https://github.com/aspidajs/aspida/workflows/Node.js%20CI/badge.svg?branch=master" alt="Node.js CI" />
<a href="https://github.com/aspida/aspida/actions?query=workflow%3A%22Node.js+CI%22">
<img src="https://github.com/aspida/aspida/workflows/Node.js%20CI/badge.svg?branch=master" alt="Node.js CI" />
</a>
<a href="https://codecov.io/gh/aspidajs/aspida">
<img src="https://img.shields.io/codecov/c/github/aspidajs/aspida.svg" alt="Codecov" />
<a href="https://codecov.io/gh/aspida/aspida">
<img src="https://img.shields.io/codecov/c/github/aspida/aspida.svg" alt="Codecov" />
</a>
<a href="https://lgtm.com/projects/g/aspidajs/aspida/context:javascript">
<img src="https://img.shields.io/lgtm/grade/javascript/g/aspidajs/aspida.svg" alt="Language grade: JavaScript" />
<a href="https://lgtm.com/projects/g/aspida/aspida/context:javascript">
<img src="https://img.shields.io/lgtm/grade/javascript/g/aspida/aspida.svg" alt="Language grade: JavaScript" />
</a>
<a href="https://dependabot.com">
<img src="https://api.dependabot.com/badges/status?host=github&repo=aspidajs/aspida" alt="Dependabot Status" />
<img src="https://api.dependabot.com/badges/status?host=github&repo=aspida/aspida" alt="Dependabot Status" />
</a>
<a href="https://github.com/aspidajs/aspida/blob/master/packages/aspida/LICENSE">
<a href="https://github.com/aspida/aspida/blob/master/packages/aspida/LICENSE">
<img src="https://img.shields.io/npm/l/aspida" alt="License" />

@@ -41,4 +41,4 @@ </a>

<div align="center">
<a href="https://github.com/aspidajs/aspida/tree/master/packages/aspida#readme">🇺🇸English</a> |
<a href="https://github.com/aspidajs/aspida/tree/master/packages/aspida/docs/ja#readme">🇯🇵日本語</a>
<a href="https://github.com/aspida/aspida/tree/master/packages/aspida#readme">🇺🇸English</a> |
<a href="https://github.com/aspida/aspida/tree/master/packages/aspida/docs/ja#readme">🇯🇵日本語</a>
</div>

@@ -74,3 +74,3 @@ <br />

<br />
<img src="https://aspidajs.github.io/aspida/assets/images/vscode.gif" width="720" alt="vscode" />
<img src="https://aspida.github.io/aspida/assets/images/vscode.gif" width="720" alt="vscode" />
<br />

@@ -80,6 +80,6 @@

1. Reproduce the endpoint directory structure in the apis directory
1. Reproduce the endpoint directory structure in the "api" directory
1. Export a Type alias named "Methods"
1. Call 'aspida --build' with npm scripts
1. API type definition file 'apis/\$api.ts' will be generated, so import the application and make an HTTP request
1. Call "aspida" with npm scripts
1. API type definition file "api/\$api.ts" will be generated, so import the application and make an HTTP request

@@ -102,6 +102,6 @@ ## Getting Started

### Create apis directory
### Create "api" directory
```sh
$ mkdir apis
$ mkdir api
```

@@ -114,3 +114,3 @@

`apis/v1/users/index.ts`
`api/v1/users/index.ts`

@@ -145,3 +145,3 @@ ```typescript

`apis/v1/users/_userId@number.ts`
`api/v1/users/_userId@number.ts`

@@ -179,3 +179,3 @@ Specify the type of path variable “userId” starting with underscore with “@number”

"scripts": {
"api:build": "aspida --build"
"api:build": "aspida"
}

@@ -188,3 +188,3 @@ }

> apis/$api.ts was built successfully.
> api/$api.ts was built successfully.
```

@@ -198,3 +198,3 @@

import aspida from "@aspida/axios"
import api from "../apis/$api"
import api from "../api/$api"
;(async () => {

@@ -210,3 +210,3 @@ const userId = 0

// req -> GET: /v1/users/?limit=10
// res -> { status: 200, body: [{ id: 0, name: 'taro' }], headers: {...} }
// res -> { status: 200, body: [{ id: 0, name: "taro" }], headers: {...} }

@@ -216,3 +216,3 @@ const user = await client.v1.users._userId(userId).$get()

// req -> GET: /v1/users/0
// res -> { id: 0, name: 'taro' }
// res -> { id: 0, name: "taro" }
})()

@@ -227,6 +227,6 @@ ```

- **[aspida-axios](https://github.com/aspidajs/aspida/tree/develop/packages/aspida-axios#readme)**
- **[aspida-ky](https://github.com/aspidajs/aspida/tree/develop/packages/aspida-ky#readme)**
- **[aspida-fetch](https://github.com/aspidajs/aspida/tree/develop/packages/aspida-fetch#readme)**
- **[aspida-node-fetch](https://github.com/aspidajs/aspida/tree/develop/packages/aspida-node-fetch#readme)**
- **[aspida-axios](https://github.com/aspida/aspida/tree/develop/packages/aspida-axios#readme)**
- **[aspida-ky](https://github.com/aspida/aspida/tree/develop/packages/aspida-ky#readme)**
- **[aspida-fetch](https://github.com/aspida/aspida/tree/develop/packages/aspida-fetch#readme)**
- **[aspida-node-fetch](https://github.com/aspida/aspida/tree/develop/packages/aspida-node-fetch#readme)**

@@ -246,11 +246,2 @@ ## Command Line Interface Options

<tr>
<td nowrap><code>--build</code><br /><code>-b</code></td>
<td></td>
<td></td>
<td>
Generate <code>$api.ts</code> required for
aspida routing.
</td>
</tr>
<tr>
<td nowrap><code>--config</code><br /><code>-c</code></td>

@@ -284,3 +275,3 @@ <td><code>string</code></td>

| ------------- | ------- | ------------- | ----------------------------------------------------- |
| input | string | "apis", "api" | Specifies the endpoint type definition root directory |
| input | string | "api", "apis" | Specifies the endpoint type definition root directory |
| baseURL | string | "" | Specify baseURL of the request |

@@ -290,5 +281,39 @@ | trailingSlash | boolean | false | Append `/` to the request URL |

## Node.js API
```ts
import { build, watch, version } from "aspida/dist/commands"
console.log(version()) // 0.1.0
build()
build("./app/aspida.config.js")
build({ input: "api1" })
build([
{ baseURL: "https://example.com/v1" },
{
input: "api2",
baseURL: "https://example.com/v2",
trailingSlash: true,
outputEachDir: true
}
])
watch()
watch("./app/aspida.config.js")
watch({ input: "api1" })
watch([
{ baseURL: "https://example.com/v1" },
{
input: "api2",
baseURL: "https://example.com/v2",
trailingSlash: true,
outputEachDir: true
}
])
```
## Tips
### Change the directory where type definition file is placed to other than apis
### Change the directory where type definition file is placed to other than "api"

@@ -306,3 +331,3 @@ Create a configuration file at the root of the project

```javascript
module.exports = { input: "apis", baseURL: "https://example.com/api" }
module.exports = { baseURL: "https://example.com/api" }
```

@@ -313,3 +338,6 @@

```javascript
module.exports = [{ input: "api1" }, { input: "api2", baseURL: "https://example.com/api" }]
module.exports = [
{ input: "api1" },
{ input: "api2", baseURL: "https://example.com/api" }
]
```

@@ -328,3 +356,3 @@

import aspida from "@aspida/axios"
import api from "../apis/$api"
import api from "../api/$api"
;(async () => {

@@ -341,3 +369,3 @@ const client = api(

// req -> GET: /v1/users/?ids=1&ids=2&ids=3
// res -> [{ id: 1, name: 'taro1' }, { id: 2, name: 'taro2' }, { id: 3, name: 'taro3' }]
// res -> [{ id: 1, name: "taro1" }, { id: 2, name: "taro2" }, { id: 3, name: "taro3" }]
})()

@@ -348,3 +376,3 @@ ```

`apis/v1/users/index.ts`
`api/v1/users/index.ts`

@@ -373,3 +401,3 @@ ```typescript

import aspida from "@aspida/axios"
import api from "../apis/$api"
import api from "../api/$api"
;(async () => {

@@ -386,3 +414,3 @@ const client = api(aspida())

// req -> POST: h/v1/users
// res -> { id: 0, name: 'taro' }
// res -> { id: 0, name: "taro" }
})()

@@ -393,3 +421,3 @@ ```

`apis/v1/users/index.ts`
`api/v1/users/index.ts`

@@ -417,3 +445,3 @@ ```typescript

import aspida from "@aspida/axios"
import api from "../apis/$api"
import api from "../api/$api"
;(async () => {

@@ -425,3 +453,3 @@ const client = api(aspida())

// req -> POST: /v1/users
// res -> { id: 0, name: 'taro' }
// res -> { id: 0, name: "taro" }
})()

@@ -432,3 +460,3 @@ ```

`apis/v1/users/index.ts`
`api/v1/users/index.ts`

@@ -451,3 +479,3 @@ ```typescript

import aspida from "@aspida/axios"
import api from "../apis/$api"
import api from "../api/$api"
;(async () => {

@@ -465,19 +493,12 @@ const client = api(aspida())

`aspida.config.js`
Compatible with yaml/json of OpenAPI3.0/Swagger2.0
```js
module.exports = {
input: "apis", // "input" of aspida is "output" for openapi2aspida
openapi: { inputFile: "https://petstore.swagger.io/v2/swagger.json" } // Compatible with yaml/json of OpenAPI3.0/Swagger2.0
}
```
`tarminal`
```sh
$ npx openapi2aspida --build
# apis/$api.ts was built successfully.
$ npx openapi2aspida -i https://petstore.swagger.io/v2/swagger.json
# api/$api.ts was built successfully.
```
[Docs of openapi2aspida](https://github.com/aspidajs/openapi2aspida)
[Docs of openapi2aspida](https://github.com/aspida/openapi2aspida)

@@ -489,3 +510,3 @@ ### Define endpoints that contain special characters

`apis/foo%3Abar.ts`
`api/foo%3Abar.ts`

@@ -506,3 +527,3 @@ ```ts

import aspida from "@aspida/axios"
import api from "../apis/$api"
import api from "../api/$api"
;(async () => {

@@ -519,3 +540,3 @@ const client = api(aspida())

If you don't need to use all of `apis/$api.ts` , you can split them up and import only part of them
If you don't need to use all of `api/$api.ts` , you can split them up and import only part of them
`outputEachDir` option generates `$api.ts` in each endpoint directory

@@ -527,6 +548,3 @@ `$api.ts` will not be generated under the directory containing the path variable

```js
module.exports = {
input: "apis",
outputEachDir: true
}
module.exports = { outputEachDir: true }
```

@@ -540,4 +558,4 @@

import aspida from "@aspida/axios"
import api0 from "../apis/v1/foo/$api"
import api1 from "../apis/v2/bar/$api"
import api0 from "../api/v1/foo/$api"
import api1 from "../api/v2/bar/$api"
;(async () => {

@@ -558,3 +576,3 @@ const aspidaClient = aspida()

<a href="https://twitter.com/solufa2020">
<img src="https://aspidajs.github.io/aspida/assets/images/twitter.svg" width="50" alt="Twitter" />
<img src="https://aspida.github.io/aspida/assets/images/twitter.svg" width="50" alt="Twitter" />
</a>

@@ -564,8 +582,8 @@

aspida is licensed under a [MIT License](https://github.com/aspidajs/aspida/blob/master/packages/aspida/LICENSE).
aspida is licensed under a [MIT License](https://github.com/aspida/aspida/blob/master/packages/aspida/LICENSE).
[aspida-mock]: https://github.com/aspidajs/aspida/tree/master/packages/aspida-mock
[@aspida/axios]: https://github.com/aspidajs/aspida/tree/master/packages/aspida-axios
[@aspida/ky]: https://github.com/aspidajs/aspida/tree/master/packages/aspida-ky
[@aspida/fetch]: https://github.com/aspidajs/aspida/tree/master/packages/aspida-fetch
[@aspida/node-fetch]: https://github.com/aspidajs/aspida/tree/master/packages/aspida-node-fetch
[aspida-mock]: https://github.com/aspida/aspida/tree/master/packages/aspida-mock
[@aspida/axios]: https://github.com/aspida/aspida/tree/master/packages/aspida-axios
[@aspida/ky]: https://github.com/aspida/aspida/tree/master/packages/aspida-ky
[@aspida/fetch]: https://github.com/aspida/aspida/tree/master/packages/aspida-fetch
[@aspida/node-fetch]: https://github.com/aspida/aspida/tree/master/packages/aspida-node-fetch

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc