simple-github-gist-api 2.0.5 → 2.0.9
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 +21 -0
- package/README.md +43 -52
- package/package.json +32 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Vighnesh Raut
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,65 +1,20 @@
|
|
|
1
1
|
# Simple Github Gist API
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
</p>
|
|
9
|
-
|
|
10
|
-
> This documentation is for v2 of the lib. v2 has a few breaking changes.
|
|
11
|
-
>
|
|
12
|
-
> You can find the v1 documentation in the `docs` directory (On Github).
|
|
3
|
+
[](https://www.npmjs.com/package/simple-github-gist-api)
|
|
4
|
+
[](https://img.shields.io/bundlephobia/minzip/simple-github-gist-api)
|
|
5
|
+
[](https://img.shields.io/npm/dt/simple-github-gist-api)
|
|
6
|
+
[](https://github.com/vighnesh153/simple-github-gist-api/blob/master/LICENSE)
|
|
7
|
+
[](https://github.com/vighnesh153/simple-github-gist-api/issues)
|
|
13
8
|
|
|
14
9
|
Use this promise based API to
|
|
15
10
|
store data on your github gists without the
|
|
16
11
|
need to make those tedious HTTP requests.
|
|
17
12
|
|
|
18
|
-
> Note:
|
|
19
|
-
> it is a new commit and the commit-id changes. So, when you save,
|
|
20
|
-
> don't do that simultaneously.
|
|
21
|
-
>
|
|
22
|
-
> For instance, assume you are using this in your API.
|
|
23
|
-
> And you have an endpoint `/create-file`.
|
|
24
|
-
>
|
|
25
|
-
> Think multiple people making request at the same time:
|
|
26
|
-
```
|
|
27
|
-
/create-file?name=1.json
|
|
28
|
-
/create-file?name=2.json
|
|
29
|
-
/create-file?name=3.json
|
|
30
|
-
...
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
> If this happens at the same time, then we cannot guarantee that the
|
|
34
|
-
> all the files will be saved. Maybe when creating both 2.json and 3.json,
|
|
35
|
-
> we are making use of the same commit-id. Both will work but 1 will over-write
|
|
36
|
-
> the other commit.
|
|
37
|
-
>
|
|
38
|
-
> But if you do:
|
|
39
|
-
|
|
40
|
-
```ts
|
|
41
|
-
const file1 = gist.createFile('1.json', "{}")
|
|
42
|
-
const file2 = gist.createFile('2.json', "{}")
|
|
43
|
-
const file3 = gist.createFile('3.json', "{}")
|
|
44
|
-
|
|
45
|
-
await file1.save();
|
|
46
|
-
await file2.save();
|
|
47
|
-
await file3.save();
|
|
48
|
-
```
|
|
49
|
-
>
|
|
50
|
-
> this will work as the latest commit-id will be fetched when
|
|
51
|
-
> saving the next file.
|
|
52
|
-
>
|
|
53
|
-
> Or
|
|
54
|
-
```ts
|
|
55
|
-
gist.save();
|
|
56
|
-
```
|
|
57
|
-
> this will work as well because all the changes will go in a single commit.
|
|
58
|
-
|
|
13
|
+
> Note: This documentation is for v2 of the lib. v2 has a few breaking changes. You can find the v1 documentation in the `docs` directory (On Github).
|
|
59
14
|
|
|
60
15
|
## Installation
|
|
61
16
|
|
|
62
|
-
```
|
|
17
|
+
```sh
|
|
63
18
|
npm i -S simple-github-gist-api
|
|
64
19
|
```
|
|
65
20
|
|
|
@@ -174,6 +129,42 @@ await gist.save();
|
|
|
174
129
|
```
|
|
175
130
|
> Only files that have un-saved changes will be saved.
|
|
176
131
|
|
|
132
|
+
### Gotchas
|
|
133
|
+
|
|
134
|
+
Github Gist's API work on commit-id basis. If you save anything,
|
|
135
|
+
it is a new commit and the commit-id changes. So, when you save,
|
|
136
|
+
don't do that simultaneously.
|
|
137
|
+
|
|
138
|
+
For instance, assume you have an endpoint `/create-file`. And if multiple people making request at the same time:
|
|
139
|
+
```
|
|
140
|
+
/create-file?name=1.json
|
|
141
|
+
/create-file?name=2.json
|
|
142
|
+
/create-file?name=3.json
|
|
143
|
+
...
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
then we cannot guarantee that the
|
|
147
|
+
all the files will be saved. When creating `2.json` and `3.json`, there is a possibility
|
|
148
|
+
that we make use of the same commit-id at HEAD. Both will work but 1 will over-write
|
|
149
|
+
the other commit.
|
|
150
|
+
|
|
151
|
+
But if you do the following, it will work as the latest commit-id will be fetched when
|
|
152
|
+
saving each file.
|
|
153
|
+
```ts
|
|
154
|
+
const file1 = gist.createFile('1.json', "{}")
|
|
155
|
+
const file2 = gist.createFile('2.json', "{}")
|
|
156
|
+
const file3 = gist.createFile('3.json', "{}")
|
|
157
|
+
|
|
158
|
+
await file1.save();
|
|
159
|
+
await file2.save();
|
|
160
|
+
await file3.save();
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Or even this will work as well because all the changes will be pushed in a single commit.
|
|
164
|
+
```ts
|
|
165
|
+
gist.save();
|
|
166
|
+
```
|
|
167
|
+
|
|
177
168
|
### Sample
|
|
178
169
|
```ts
|
|
179
170
|
import GithubGist from "./src";
|
package/package.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-github-gist-api",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "A way to store data on Github Gist.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "jest --config jestconfig.json",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
9
|
+
"prepare": "husky install",
|
|
10
|
+
"cleanup": "rimraf dist",
|
|
11
|
+
"build:pre-requisite": "npm run test",
|
|
12
|
+
"build:declaration": "tsc",
|
|
13
|
+
"build": "npm run cleanup && npm run build:pre-requisite && npm-run-all build:*",
|
|
14
|
+
"test:watch": "jest --watch",
|
|
15
|
+
"prettier:fix": "prettier -w ./src/**/*.ts -w ./src/**/*.tsx --no-error-on-unmatched-pattern true",
|
|
16
|
+
"lint:fix": "eslint --fix ./src/**/*.ts --fix ./src/**/*.tsx --no-error-on-unmatched-pattern true",
|
|
17
|
+
"git:rebase": "git fetch && git rebase origin/master",
|
|
18
|
+
"release": "npm run git:rebase && npm run build && standard-version && git push --follow-tags && npm publish --access=public",
|
|
19
|
+
"lint": "eslint src/*"
|
|
12
20
|
},
|
|
13
21
|
"files": [
|
|
14
22
|
"dist/**/*"
|
|
@@ -32,12 +40,31 @@
|
|
|
32
40
|
},
|
|
33
41
|
"homepage": "https://github.com/vighnesh153/simple-github-gist-api#readme",
|
|
34
42
|
"devDependencies": {
|
|
43
|
+
"@commitlint/cli": "^15.0.0",
|
|
44
|
+
"@commitlint/config-conventional": "^15.0.0",
|
|
35
45
|
"@types/jest": "^27.0.2",
|
|
46
|
+
"eslint": "^8.4.1",
|
|
47
|
+
"eslint-config-airbnb": "^19.0.2",
|
|
48
|
+
"eslint-config-node": "^4.1.0",
|
|
49
|
+
"eslint-config-prettier": "^8.3.0",
|
|
50
|
+
"eslint-plugin-import": "^2.25.3",
|
|
51
|
+
"eslint-plugin-jsx-a11y": "^6.5.1",
|
|
52
|
+
"eslint-plugin-node": "^11.1.0",
|
|
53
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
54
|
+
"eslint-plugin-react": "^7.27.1",
|
|
55
|
+
"eslint-plugin-react-hooks": "^4.3.0",
|
|
56
|
+
"husky": "^7.0.4",
|
|
36
57
|
"jest": "^27.3.0",
|
|
58
|
+
"lint-staged": "^12.1.2",
|
|
59
|
+
"npm-run-all": "^4.1.5",
|
|
60
|
+
"prettier": "^2.5.1",
|
|
61
|
+
"rimraf": "^3.0.2",
|
|
62
|
+
"semantic-release": "^18.0.1",
|
|
63
|
+
"standard-version": "^9.3.2",
|
|
37
64
|
"ts-jest": "^27.0.7",
|
|
38
65
|
"typescript": "^4.4.4"
|
|
39
66
|
},
|
|
40
67
|
"dependencies": {
|
|
41
|
-
"axios": "^0.
|
|
68
|
+
"axios": "^0.24.0"
|
|
42
69
|
}
|
|
43
70
|
}
|