Socket
Socket
Sign inDemoInstall

aspida

Package Overview
Dependencies
Maintainers
3
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 1.12.0 to 1.13.0

dist/cjs/buildTemplate.d.ts

2

bin/index.js
#!/usr/bin/env node
require('../dist/cli').run(process.argv.slice(2))
require('../dist/cjs/cli').run(process.argv.slice(2))
{
"name": "aspida",
"version": "1.12.0",
"version": "1.13.0",
"description": "TypeScript friendly HTTP client wrapper for the browser and node.js",
"author": "Solufa <solufa2020@gmail.com>",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": "bin/index.js",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"bin": "./bin/index.js",
"exports": {
".": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts"
},
"./package.json": "./package.json"
},
"homepage": "https://github.com/aspida/aspida#readme",

@@ -31,4 +39,4 @@ "repository": {

"form-data": "^4.0.0",
"minimist": "^1.2.6"
"minimist": "^1.2.8"
}
}
}
# aspida
<br />

@@ -11,11 +12,2 @@ <img src="https://aspida.github.io/aspida/logos/png/logo.png" alt="aspida" title="aspida" />

</a>
<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/aspida/aspida">
<img src="https://img.shields.io/codecov/c/github/aspida/aspida.svg" alt="Codecov" />
</a>
<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>
</div>

@@ -77,23 +69,25 @@ <br />

```typescript
```ts
import type { DefineMethods } from "aspida";
type User = {
id: number
name: string
}
id: number;
name: string;
};
export type Methods = {
export type Methods = DefineMethods<{
get: {
query?: {
limit: number
}
limit: number;
};
resBody: User[]
}
resBody: User[];
};
post: {
reqBody: {
name: string
}
name: string;
};
resBody: User
resBody: User;
/**

@@ -106,4 +100,4 @@ * reqHeaders(?): ...

*/
}
}
};
}>;
```

@@ -119,21 +113,23 @@

```typescript
```ts
import type { DefineMethods } from "aspida";
type User = {
id: number
name: string
}
id: number;
name: string;
};
export type Methods = {
export type Methods = DefineMethods<{
get: {
resBody: User
}
resBody: User;
};
put: {
reqBody: {
name: string
}
name: string;
};
resBody: User
}
}
resBody: User;
};
}>;
```

@@ -163,22 +159,22 @@

```typescript
import aspida from "@aspida/axios"
import api from "../api/$api"
;(async () => {
const userId = 0
const limit = 10
const client = api(aspida())
```ts
import aspida from "@aspida/axios";
import api from "../api/$api";
(async () => {
const userId = 0;
const limit = 10;
const client = api(aspida());
await client.v1.users.post({ body: { name: "taro" } })
await client.v1.users.post({ body: { name: "taro" } });
const res = await client.v1.users.get({ query: { limit } })
console.log(res)
const res = await client.v1.users.get({ query: { limit } });
console.log(res);
// req -> GET: /v1/users/?limit=10
// res -> { status: 200, body: [{ id: 0, name: "taro" }], headers: {...} }
const user = await client.v1.users._userId(userId).$get()
console.log(user)
const user = await client.v1.users._userId(userId).$get();
console.log(user);
// req -> GET: /v1/users/0
// res -> { id: 0, name: "taro" }
})()
})();
```

@@ -231,9 +227,9 @@

| Option | Type | Default | Description |
| -------------------- | ------------------------------------ | ------------- | ----------------------------------------------------- |
| input | string | "api" | Specifies the endpoint type definition root directory |
| baseURL | string | "" | Specify baseURL of the request |
| trailingSlash | boolean | false | Append `/` to the request URL |
| outputEachDir | boolean | false | Generate `$api.ts` in each endpoint directory |
| outputMode (>=1.6.0) | "all" \| "normalOnly" \| "aliasOnly" | "all" | Output either `get` or `$get` for compression |
| Option | Type | Default | Description |
| -------------------- | ------------------------------------ | ------- | ----------------------------------------------------- |
| input | string | "api" | Specifies the endpoint type definition root directory |
| baseURL | string | "" | Specify baseURL of the request |
| trailingSlash | boolean | false | Append `/` to the request URL |
| outputEachDir | boolean | false | Generate `$api.ts` in each endpoint directory |
| outputMode (>=1.6.0) | "all" \| "normalOnly" \| "aliasOnly" | "all" | Output either `get` or `$get` for compression |

@@ -243,9 +239,9 @@ ## Node.js API

```ts
import { version, build, watch } from "aspida/dist/commands"
import { version, build, watch } from "aspida/dist/commands";
console.log(version()) // 0.x.y
console.log(version()); // 0.x.y
build()
build("./app/aspida.config.js")
build({ input: "api1" })
build();
build("./app/aspida.config.js");
build({ input: "api1" });
build([

@@ -258,9 +254,9 @@ { baseURL: "https://example.com/v1" },

outputEachDir: true,
outputMode: 'all'
}
])
outputMode: "all",
},
]);
watch()
watch("./app/aspida.config.js")
watch({ input: "api1" })
watch();
watch("./app/aspida.config.js");
watch({ input: "api1" });
watch([

@@ -273,5 +269,5 @@ { baseURL: "https://example.com/v1" },

outputEachDir: true,
outputMode: 'all'
}
])
outputMode: "all",
},
]);
```

@@ -311,3 +307,3 @@

```javascript
module.exports = { input: "src" }
module.exports = { input: "src" };
```

@@ -318,3 +314,3 @@

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

@@ -325,6 +321,3 @@

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

@@ -341,20 +334,20 @@

```typescript
import axios from "axios"
import qs from "qs"
import aspida from "@aspida/axios"
import api from "../api/$api"
;(async () => {
```ts
import axios from "axios";
import qs from "qs";
import aspida from "@aspida/axios";
import api from "../api/$api";
(async () => {
const client = api(
aspida(axios, { paramsSerializer: params => qs.stringify(params, { indices: false }) })
)
);
const users = await client.v1.users.$get({
// config: { paramsSerializer: (params) => qs.stringify(params, { indices: false }) },
query: { ids: [1, 2, 3] }
})
console.log(users)
query: { ids: [1, 2, 3] },
});
console.log(users);
// req -> GET: /v1/users/?ids=1&ids=2&ids=3
// res -> [{ id: 1, name: "taro1" }, { id: 2, name: "taro2" }, { id: 3, name: "taro3" }]
})()
})();
```

@@ -368,20 +361,21 @@

```typescript
import type { ReadStream } from 'fs'
```ts
import type { DefineMethods } from "aspida";
import type { ReadStream } from "fs";
export type Methods = {
export type Methods = DefineMethods<{
post: {
reqFormat: FormData
reqFormat: FormData;
reqBody: {
name: string
icon: File | ReadStream
}
name: string;
icon: File | ReadStream;
};
resBody: {
id: number
name: string
}
}
}
id: number;
name: string;
};
};
}>;
```

@@ -391,7 +385,7 @@

```typescript
import aspida from "@aspida/axios"
import api from "../api/$api"
;(async () => {
const client = api(aspida())
```ts
import aspida from "@aspida/axios";
import api from "../api/$api";
(async () => {
const client = api(aspida());

@@ -401,9 +395,9 @@ const user = await client.v1.users.$post({

name: "taro",
icon: imageFile
}
})
console.log(user)
icon: imageFile,
},
});
console.log(user);
// req -> POST: h/v1/users
// res -> { id: 0, name: "taro" }
})()
})();
```

@@ -415,19 +409,19 @@

```typescript
import fs from 'fs'
import aspida from "@aspida/axios"
import api from "../api/$api"
;(async () => {
const client = api(aspida())
const fileName = 'images/sample.jpg'
```ts
import fs from "fs";
import aspida from "@aspida/axios";
import api from "../api/$api";
(async () => {
const client = api(aspida());
const fileName = "images/sample.jpg";
const user = await client.v1.users.$post({
body: {
name: "taro",
icon: fs.createReadStream(fileName)
}
})
console.log(user)
icon: fs.createReadStream(fileName),
},
});
console.log(user);
// req -> POST: h/v1/users
// res -> { id: 0, name: "taro" }
})()
})();
```

@@ -441,17 +435,19 @@

```typescript
export type Methods = {
```ts
import type { DefineMethods } from "aspida";
export type Methods = DefineMethods<{
post: {
reqFormat: URLSearchParams
reqFormat: URLSearchParams;
reqBody: {
name: string
}
name: string;
};
resBody: {
id: number
name: string
}
}
}
id: number;
name: string;
};
};
}>;
```

@@ -461,13 +457,13 @@

```typescript
import aspida from "@aspida/axios"
import api from "../api/$api"
;(async () => {
const client = api(aspida())
```ts
import aspida from "@aspida/axios";
import api from "../api/$api";
(async () => {
const client = api(aspida());
const user = await client.v1.users.$post({ body: { name: "taro" } })
console.log(user)
const user = await client.v1.users.$post({ body: { name: "taro" } });
console.log(user);
// req -> POST: /v1/users
// res -> { id: 0, name: "taro" }
})()
})();
```

@@ -481,12 +477,14 @@

```typescript
export type Methods = {
```ts
import type { DefineMethods } from "aspida";
export type Methods = DefineMethods<{
get: {
query: {
name: string
}
name: string;
};
resBody: ArrayBuffer
}
}
resBody: ArrayBuffer;
};
}>;
```

@@ -496,13 +494,13 @@

```typescript
import aspida from "@aspida/axios"
import api from "../api/$api"
;(async () => {
const client = api(aspida())
```ts
import aspida from "@aspida/axios";
import api from "../api/$api";
(async () => {
const client = api(aspida());
const user = await client.v1.users.$get({ query: { name: "taro" } })
console.log(user)
const user = await client.v1.users.$get({ query: { name: "taro" } });
console.log(user);
// req -> GET: /v1/users/?name=taro
// res -> ArrayBuffer
})()
})();
```

@@ -518,5 +516,5 @@

type User = {
id: number
name: string
}
id: number;
name: string;
};

@@ -526,3 +524,3 @@ export interface Methods {

// common properties
reqFormat: FormData
reqFormat: FormData;
/**

@@ -539,4 +537,4 @@ * query(?): ...

{
reqBody: Omit<User, 'id'>
resBody: User
reqBody: Omit<User, "id">;
resBody: User;
/**

@@ -550,7 +548,7 @@ * query(?): ...

{
reqBody: Omit<User, 'id'>[]
resBody: User[]
reqBody: Omit<User, "id">[];
resBody: User[];
}
]
}
];
};
}

@@ -562,15 +560,15 @@ ```

```ts
import aspida from "@aspida/axios"
import api from "../api/$api"
;(async () => {
const client = api(aspida())
import aspida from "@aspida/axios";
import api from "../api/$api";
(async () => {
const client = api(aspida());
const user = await client.users.$post({ body: { name: "taro" } })
console.log(user) // { id: 0, name: "taro" }
const user = await client.users.$post({ body: { name: "taro" } });
console.log(user); // { id: 0, name: "taro" }
const users = await client.users.$post({
body: [{ name: "hanako" }, { name: "mario" }]
})
console.log(users) // [{ id: 1, name: "hanako" }, { id: 2, name: "mario" }]
})()
body: [{ name: "hanako" }, { name: "mario" }],
});
console.log(users); // [{ id: 1, name: "hanako" }, { id: 2, name: "mario" }]
})();
```

@@ -588,7 +586,9 @@

```ts
export type Methods = {
import type { DefineMethods } from "aspida";
export type Methods = DefineMethods<{
get: {
resBody: string
}
}
resBody: string;
};
}>;
```

@@ -599,7 +599,9 @@

```ts
export type Methods = {
import type { DefineMethods } from "aspida";
export type Methods = DefineMethods<{
get: {
resBody: User
}
}
resBody: User;
};
}>;
```

@@ -611,16 +613,16 @@

```typescript
import aspida from "@aspida/axios"
import api from "../api/$api"
;(async () => {
const client = api(aspida())
```ts
import aspida from "@aspida/axios";
import api from "../api/$api";
(async () => {
const client = api(aspida());
const message = await client.foo_bar.$get()
console.log(message)
const message = await client.foo_bar.$get();
console.log(message);
// req -> GET: /foo:bar
const user = await client.users._userId_read(1).$get()
console.log(user)
const user = await client.users._userId_read(1).$get();
console.log(user);
// req -> GET: /users/1:read
})()
})();
```

@@ -639,3 +641,3 @@

```js
module.exports = { outputEachDir: true }
module.exports = { outputEachDir: true };
```

@@ -647,16 +649,16 @@

```typescript
import aspida from "@aspida/axios"
import api0 from "../api/v1/foo/$api"
import api1 from "../api/v2/bar/$api"
;(async () => {
const aspidaClient = aspida()
```ts
import aspida from "@aspida/axios";
import api0 from "../api/v1/foo/$api";
import api1 from "../api/v2/bar/$api";
(async () => {
const aspidaClient = aspida();
const client = {
foo: api0(aspidaClient),
bar: api1(aspidaClient)
}
bar: api1(aspidaClient),
};
const message = await client.bar._id(1).$get()
const message = await client.bar._id(1).$get();
// req -> GET: /v2/bar/1
})()
})();
```

@@ -671,19 +673,21 @@

```ts
import aspida from "@aspida/axios"
import api from "../api/$api"
;(async () => {
const client = api(aspida())
import aspida from "@aspida/axios";
import api from "../api/$api";
(async () => {
const client = api(aspida());
console.log(client.v1.users.$path())
console.log(client.v1.users.$path());
// /v1/users
console.log(client.vi.users.$path({ query: { limit: 10 } }))
console.log(client.vi.users.$path({ query: { limit: 10 } }));
// /v1/users?limit=10
console.log(client.vi.users.$path({
method: 'post',
query: { id: 1 }
}))
console.log(
client.vi.users.$path({
method: "post",
query: { id: 1 },
})
);
// /v1/users?id=1
})()
})();
```

@@ -698,12 +702,14 @@

```ts
import type { DefineMethods } from "aspida";
/**
* root comment
*
*
* @remarks
* root remarks comment
*/
export type Methods = {
export type Methods = DefineMethods<{
/**
* post method comment
*
*
* @remarks

@@ -714,10 +720,10 @@ * post method remarks comment

/** post query comment */
query: { limit: number }
query: { limit: number };
/** post reqHeaders comment */
reqHeaders: { token: string }
reqHeaders: { token: string };
reqFormat: FormData
reqFormat: FormData;
/** post reqBody comment */
reqBody: UserCreation
reqBody: UserCreation;

@@ -728,5 +734,5 @@ /**

*/
resBody: User
}
}
resBody: User;
};
}>;
```

@@ -743,3 +749,3 @@

* root comment
*
*
* @remarks

@@ -752,6 +758,6 @@ * root remarks comment

* post method comment
*
*
* @remarks
* post method remarks comment
*
*
* @param option.query - post query comment

@@ -763,16 +769,17 @@ * @param option.headers - post reqHeaders comment

*/
$post: (option: { body: Methods0['post']['reqBody'], query: Methods0['post']['query'], headers: Methods0['post']['reqHeaders'], config?: T }) =>
fetch<Methods0['post']['resBody']>(prefix, PATH0, POST, option).json().then(r => r.body)
}
}
$post: (option: {
body: Methods0["post"]["reqBody"];
query: Methods0["post"]["query"];
headers: Methods0["post"]["reqHeaders"];
config?: T;
}) =>
fetch<Methods0["post"]["resBody"]>(prefix, PATH0, POST, option)
.json()
.then(r => r.body),
};
};
```
## Support
<a href="https://twitter.com/solufa2020">
<img src="https://aspida.github.io/aspida/assets/images/twitter.svg" width="50" alt="Twitter" />
</a>
## License
aspida is licensed under a [MIT License](https://github.com/aspida/aspida/blob/master/packages/aspida/LICENSE).

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