simple-github-gist-api 2.0.5 → 2.0.6
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 +38 -46
- package/package.json +32 -3
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
|
@@ -7,59 +7,15 @@
|
|
|
7
7
|
</a>
|
|
8
8
|
</p>
|
|
9
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).
|
|
13
|
-
|
|
14
10
|
Use this promise based API to
|
|
15
11
|
store data on your github gists without the
|
|
16
12
|
need to make those tedious HTTP requests.
|
|
17
13
|
|
|
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
|
-
|
|
14
|
+
> 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
15
|
|
|
60
16
|
## Installation
|
|
61
17
|
|
|
62
|
-
```
|
|
18
|
+
```sh
|
|
63
19
|
npm i -S simple-github-gist-api
|
|
64
20
|
```
|
|
65
21
|
|
|
@@ -174,6 +130,42 @@ await gist.save();
|
|
|
174
130
|
```
|
|
175
131
|
> Only files that have un-saved changes will be saved.
|
|
176
132
|
|
|
133
|
+
### Gotchas
|
|
134
|
+
|
|
135
|
+
Github Gist's API work on commit-id basis. If you save anything,
|
|
136
|
+
it is a new commit and the commit-id changes. So, when you save,
|
|
137
|
+
don't do that simultaneously.
|
|
138
|
+
|
|
139
|
+
For instance, assume you have an endpoint `/create-file`. And if multiple people making request at the same time:
|
|
140
|
+
```
|
|
141
|
+
/create-file?name=1.json
|
|
142
|
+
/create-file?name=2.json
|
|
143
|
+
/create-file?name=3.json
|
|
144
|
+
...
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
then we cannot guarantee that the
|
|
148
|
+
all the files will be saved. When creating `2.json` and `3.json`, there is a possibility
|
|
149
|
+
that we make use of the same commit-id at HEAD. Both will work but 1 will over-write
|
|
150
|
+
the other commit.
|
|
151
|
+
|
|
152
|
+
But if you do the following, it will work as the latest commit-id will be fetched when
|
|
153
|
+
saving each file.
|
|
154
|
+
```ts
|
|
155
|
+
const file1 = gist.createFile('1.json', "{}")
|
|
156
|
+
const file2 = gist.createFile('2.json', "{}")
|
|
157
|
+
const file3 = gist.createFile('3.json', "{}")
|
|
158
|
+
|
|
159
|
+
await file1.save();
|
|
160
|
+
await file2.save();
|
|
161
|
+
await file3.save();
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Or even this will work as well because all the changes will be pushed in a single commit.
|
|
165
|
+
```ts
|
|
166
|
+
gist.save();
|
|
167
|
+
```
|
|
168
|
+
|
|
177
169
|
### Sample
|
|
178
170
|
```ts
|
|
179
171
|
import GithubGist from "./src";
|
package/package.json
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-github-gist-api",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
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
|
-
"build": "rm -rf dist/ && tsc",
|
|
10
9
|
"prepublish": "npm run build",
|
|
11
|
-
"postpublish": "PACKAGE_VERSION=$(cat package.json | grep \\\"version\\\" | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag v$PACKAGE_VERSION && git push --tags"
|
|
10
|
+
"postpublish": "PACKAGE_VERSION=$(cat package.json | grep \\\"version\\\" | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag v$PACKAGE_VERSION && git push --tags",
|
|
11
|
+
"prepare": "husky install",
|
|
12
|
+
"cleanup": "rimraf dist",
|
|
13
|
+
"build:pre-requisite": "npm run test",
|
|
14
|
+
"build:declaration": "tsc",
|
|
15
|
+
"build": "npm run cleanup && npm run build:pre-requisite && npm-run-all build:*",
|
|
16
|
+
"test:watch": "jest --watch",
|
|
17
|
+
"prettier:fix": "prettier -w ./src/**/*.ts -w ./src/**/*.tsx --no-error-on-unmatched-pattern true",
|
|
18
|
+
"lint:fix": "eslint --fix ./src/**/*.ts --fix ./src/**/*.tsx --no-error-on-unmatched-pattern true",
|
|
19
|
+
"git:rebase": "git fetch && git rebase origin/master",
|
|
20
|
+
"release": "npm run git:rebase && npm run build && standard-version && git push --follow-tags && npm publish --access=public",
|
|
21
|
+
"lint": "eslint src/*"
|
|
12
22
|
},
|
|
13
23
|
"files": [
|
|
14
24
|
"dist/**/*"
|
|
@@ -32,8 +42,27 @@
|
|
|
32
42
|
},
|
|
33
43
|
"homepage": "https://github.com/vighnesh153/simple-github-gist-api#readme",
|
|
34
44
|
"devDependencies": {
|
|
45
|
+
"@commitlint/cli": "^15.0.0",
|
|
46
|
+
"@commitlint/config-conventional": "^15.0.0",
|
|
35
47
|
"@types/jest": "^27.0.2",
|
|
48
|
+
"eslint": "^8.4.1",
|
|
49
|
+
"eslint-config-airbnb": "^19.0.2",
|
|
50
|
+
"eslint-config-node": "^4.1.0",
|
|
51
|
+
"eslint-config-prettier": "^8.3.0",
|
|
52
|
+
"eslint-plugin-import": "^2.25.3",
|
|
53
|
+
"eslint-plugin-jsx-a11y": "^6.5.1",
|
|
54
|
+
"eslint-plugin-node": "^11.1.0",
|
|
55
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
56
|
+
"eslint-plugin-react": "^7.27.1",
|
|
57
|
+
"eslint-plugin-react-hooks": "^4.3.0",
|
|
58
|
+
"husky": "^7.0.4",
|
|
36
59
|
"jest": "^27.3.0",
|
|
60
|
+
"lint-staged": "^12.1.2",
|
|
61
|
+
"npm-run-all": "^4.1.5",
|
|
62
|
+
"prettier": "^2.5.1",
|
|
63
|
+
"rimraf": "^3.0.2",
|
|
64
|
+
"semantic-release": "^18.0.1",
|
|
65
|
+
"standard-version": "^9.3.2",
|
|
37
66
|
"ts-jest": "^27.0.7",
|
|
38
67
|
"typescript": "^4.4.4"
|
|
39
68
|
},
|