restql 1.1.6 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +38 -97
- package/dist/cjs/index.js +68 -429
- package/dist/esm/index.js +185 -0
- package/dist/umd/index.js +200 -20508
- package/dist/umd/index.min.js +1 -1
- package/package.json +46 -60
- package/dist/es/index.js +0 -544
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -4,14 +4,11 @@ RESTful API Resolver for Nested-Linked Resources | 🕸 🕷
|
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
[](https://codeclimate.com/github/relztic/restql/test_coverage/)
|
|
11
|
-
[](https://github.com/prettier/prettier/)
|
|
12
|
-
|
|
13
|
-
RestQL allows you to dynamically resolve the nested-linked resources of a RESTful API.
|
|
7
|
+
[](https://www.npmjs.com/package/restql/)
|
|
8
|
+

|
|
9
|
+

|
|
14
10
|
|
|
11
|
+
RestQL allows you to dynamically resolve the nested-linked resources of a RESTful API.
|
|
15
12
|
By specifying a set of properties to describe the paths.
|
|
16
13
|
|
|
17
14
|
## Installation
|
|
@@ -19,13 +16,7 @@ By specifying a set of properties to describe the paths.
|
|
|
19
16
|
### npm
|
|
20
17
|
|
|
21
18
|
```sh
|
|
22
|
-
npm install restql
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### Yarn
|
|
26
|
-
|
|
27
|
-
```sh
|
|
28
|
-
yarn add restql
|
|
19
|
+
npm install restql
|
|
29
20
|
```
|
|
30
21
|
|
|
31
22
|
### CDN
|
|
@@ -34,44 +25,36 @@ yarn add restql
|
|
|
34
25
|
<script src="https://unpkg.com/restql/dist/umd/index.min.js"></script>
|
|
35
26
|
```
|
|
36
27
|
|
|
37
|
-
##
|
|
38
|
-
|
|
39
|
-
### `resource`
|
|
28
|
+
## Usage
|
|
40
29
|
|
|
41
|
-
`
|
|
30
|
+
### `restql(resource, resolver[, options])`
|
|
42
31
|
|
|
43
|
-
|
|
32
|
+
#### Parameters
|
|
44
33
|
|
|
45
|
-
|
|
34
|
+
- `resource` (`string`): The resource to fetch.
|
|
35
|
+
- Self-explanatory.
|
|
46
36
|
|
|
47
|
-
|
|
37
|
+
##### Example
|
|
48
38
|
|
|
49
39
|
```js
|
|
50
40
|
'https://pokeapi.co/api/v2/pokemon/1/'
|
|
51
41
|
```
|
|
52
42
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
- `resolver` (`Object`): The resolver to apply.
|
|
44
|
+
- At every level, each property describes a path to the nested resources within the current one.
|
|
45
|
+
- RestQL resolves the sames and call the subsequent resolver against them.
|
|
46
|
+
- Until the base case (`null`) is reached; from which it returns back the merged responses.
|
|
56
47
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
At each level, each property describes a path to the nested resources within the current one.
|
|
60
|
-
|
|
61
|
-
RestQL resolves the sames and call the subsequent resolver against them...
|
|
62
|
-
|
|
63
|
-
Until the base case (`null`) is reached; from which it returns back the merged responses.
|
|
64
|
-
|
|
65
|
-
**Quantifiers**
|
|
48
|
+
##### Quantifiers
|
|
66
49
|
|
|
67
50
|
Following is a table of the quantifiers you can use:
|
|
68
51
|
|
|
69
|
-
| Quantifier | Description
|
|
70
|
-
|
|
|
71
|
-
| `[]`
|
|
72
|
-
| `?`
|
|
52
|
+
| Quantifier | Description |
|
|
53
|
+
| ---------- | ------------------------- |
|
|
54
|
+
| `[]` | Collection of properties. |
|
|
55
|
+
| `?` | Optional property. |
|
|
73
56
|
|
|
74
|
-
|
|
57
|
+
##### Example
|
|
75
58
|
|
|
76
59
|
```js
|
|
77
60
|
{
|
|
@@ -88,75 +71,33 @@ Following is a table of the quantifiers you can use:
|
|
|
88
71
|
}
|
|
89
72
|
```
|
|
90
73
|
|
|
91
|
-
|
|
74
|
+
- `[options]` (`Object`): The options to bypass.
|
|
75
|
+
- [See `RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit)
|
|
92
76
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
**Description**
|
|
96
|
-
|
|
97
|
-
[`Request Config`](https://github.com/axios/axios/#request-config)
|
|
98
|
-
|
|
99
|
-
**e.g.:**
|
|
77
|
+
##### Example
|
|
100
78
|
|
|
101
79
|
```js
|
|
102
|
-
{
|
|
103
|
-
// ...
|
|
104
|
-
}
|
|
80
|
+
{ ... }
|
|
105
81
|
```
|
|
106
82
|
|
|
107
|
-
|
|
83
|
+
#### Returns
|
|
108
84
|
|
|
109
|
-
|
|
110
|
-
// External Packages
|
|
111
|
-
import restql from 'restql'
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* @constant {string} resource The resource to fetch.
|
|
115
|
-
*/
|
|
116
|
-
const resource = 'https://pokeapi.co/api/v2/pokemon/1/'
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* @constant {Object} resolver The resolver to apply.
|
|
120
|
-
*/
|
|
121
|
-
const resolver = {
|
|
122
|
-
'abilities[]?.ability.url': {
|
|
123
|
-
'generation.url': {
|
|
124
|
-
'main_region.url': null,
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
'stats[].stat.url?': {
|
|
128
|
-
'affecting_natures.increase[].url': null,
|
|
129
|
-
'affecting_natures.decrease[].url': null,
|
|
130
|
-
},
|
|
131
|
-
'moves[].move?.url': null,
|
|
132
|
-
}
|
|
85
|
+
(`Promise<Object>`): A promise which resolves into an object.
|
|
133
86
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// ...
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
(async () => {
|
|
142
|
-
try {
|
|
143
|
-
const data = await restql(resource, resolver, options)
|
|
144
|
-
|
|
145
|
-
console.log(data)
|
|
146
|
-
} catch (error) {
|
|
147
|
-
console.error(error.message)
|
|
148
|
-
}
|
|
149
|
-
})()
|
|
87
|
+
## Try It
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
npm run playground
|
|
150
91
|
```
|
|
151
92
|
|
|
152
|
-
[
|
|
93
|
+
[See Playground](https://github.com/relztic/restql/blob/main/playground/index.js)
|
|
153
94
|
|
|
154
95
|
## Roadmap
|
|
155
96
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
97
|
+
- ~~Support for authentication~~
|
|
98
|
+
- ~~Support for optional resolvers~~
|
|
99
|
+
- ~~Improve package bundler~~
|
|
100
|
+
- ~~Ability to cache responses~~
|
|
101
|
+
- Support for recursive resolvers
|
|
161
102
|
|
|
162
|
-
Take
|
|
103
|
+
> Take 🎂, Folks! 🌮 🐴 💨
|