@sparted/shared-library 1.0.8-alpha.0 → 1.0.8-alpha.1

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.
@@ -0,0 +1,20 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ export declare type GetFileContentArgs = {
3
+ path: string;
4
+ branch: string;
5
+ };
6
+ export declare type GetFileContentResponse = string;
7
+ export declare type GetFileContent = (args: GetFileContentArgs) => Promise<GetFileContentResponse>;
8
+ export declare type GetFileContentFactory = (instance: AxiosInstance) => GetFileContent;
9
+ /**
10
+ * Get the content of a file
11
+ *
12
+ * @param path the path of the file
13
+ * @param branch the branch of the file
14
+ * @returns GetFileContentResponse
15
+ * @throws validation-failed-or-the-endpoint-has-been-spammed
16
+ * @throws internal-server-error
17
+ * @throws forbidden
18
+ * @throws resource-not-found
19
+ */
20
+ export declare const getFileContentFactory: GetFileContentFactory;
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../_virtual/_tslib.js');
6
+ var utils = require('../commits/utils.js');
7
+
8
+ /**
9
+ * Get the content of a file
10
+ *
11
+ * @param path the path of the file
12
+ * @param branch the branch of the file
13
+ * @returns GetFileContentResponse
14
+ * @throws validation-failed-or-the-endpoint-has-been-spammed
15
+ * @throws internal-server-error
16
+ * @throws forbidden
17
+ * @throws resource-not-found
18
+ */
19
+ const getFileContentFactory = (instance) => (args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
20
+ const { path, branch } = args;
21
+ try {
22
+ const { data } = yield instance.get(`/contents/${path}`, {
23
+ params: {
24
+ ref: branch,
25
+ },
26
+ });
27
+ if (data.encoding === 'base64') {
28
+ return Buffer.from(data.content, 'base64').toString('utf-8');
29
+ }
30
+ return data.content;
31
+ }
32
+ catch (error) {
33
+ throw utils.handleError(error);
34
+ }
35
+ });
36
+
37
+ exports.getFileContentFactory = getFileContentFactory;
38
+ //# sourceMappingURL=get-file-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-file-content.js","sources":["../../../src/github/contents/get-file-content.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\n\nimport { handleError } from '../commits/utils';\n\nexport type GetFileContentArgs = {\n path: string;\n branch: string;\n};\n\ntype ApiResponse = {\n encoding: 'base64' | 'utf-8';\n content: string;\n};\n\nexport type GetFileContentResponse = string;\n\nexport type GetFileContent = (args: GetFileContentArgs) => Promise<GetFileContentResponse>;\n\nexport type GetFileContentFactory = (instance: AxiosInstance) => GetFileContent;\n\n/**\n * Get the content of a file\n *\n * @param path the path of the file\n * @param branch the branch of the file\n * @returns GetFileContentResponse\n * @throws validation-failed-or-the-endpoint-has-been-spammed\n * @throws internal-server-error\n * @throws forbidden\n * @throws resource-not-found\n */\nexport const getFileContentFactory: GetFileContentFactory = (instance) => async (args) => {\n const { path, branch } = args;\n\n try {\n const { data } = await instance.get<ApiResponse>(`/contents/${path}`, {\n params: {\n ref: branch,\n },\n });\n\n if (data.encoding === 'base64') {\n return Buffer.from(data.content, 'base64').toString('utf-8');\n }\n\n return data.content;\n } catch (error) {\n throw handleError(error);\n }\n};\n"],"names":["__awaiter","handleError"],"mappings":";;;;;;;AAoBA;;;;;;;;;;AAUG;AACI,MAAM,qBAAqB,GAA0B,CAAC,QAAQ,KAAK,CAAO,IAAI,KAAIA,gBAAA,CAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,KAAA,CAAA,EAAA,aAAA;AACvF,IAAA,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAE9B,IAAI;AACF,QAAA,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAc,CAAA,UAAA,EAAa,IAAI,CAAA,CAAE,EAAE;AACpE,YAAA,MAAM,EAAE;AACN,gBAAA,GAAG,EAAE,MAAM;AACZ,aAAA;AACF,SAAA,CAAC,CAAC;AAEH,QAAA,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE;AAC9B,YAAA,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC9D,SAAA;QAED,OAAO,IAAI,CAAC,OAAO,CAAC;AACrB,KAAA;AAAC,IAAA,OAAO,KAAK,EAAE;AACd,QAAA,MAAMC,iBAAW,CAAC,KAAK,CAAC,CAAC;AAC1B,KAAA;AACH,CAAC;;;;"}
@@ -1,4 +1,5 @@
1
1
  import type { CreateGitTree, CreateGitBlob, CreateGitCommit, GetTreeByCommitSha, GetShaLastCommitOfBranch, RunNewCommitProcess } from './commits';
2
+ import { GetFileContent } from './contents/get-file-content';
2
3
  export declare type GithubSdkArgs = {
3
4
  owner: string;
4
5
  repo: string;
@@ -11,6 +12,7 @@ export declare type GithubSdkInstance = {
11
12
  getShaLastCommitOfBranch: GetShaLastCommitOfBranch;
12
13
  getTreeByCommitSha: GetTreeByCommitSha;
13
14
  runNewCommitProcess: RunNewCommitProcess;
15
+ getFileContent: GetFileContent;
14
16
  };
15
17
  export declare const githubSdk: (args: GithubSdkArgs) => {
16
18
  createGitBlob: CreateGitBlob;
@@ -19,4 +21,5 @@ export declare const githubSdk: (args: GithubSdkArgs) => {
19
21
  getShaLastCommitOfBranch: GetShaLastCommitOfBranch;
20
22
  getTreeByCommitSha: GetTreeByCommitSha;
21
23
  runNewCommitProcess: RunNewCommitProcess;
24
+ getFileContent: GetFileContent;
22
25
  };
@@ -9,6 +9,7 @@ var createGitTree = require('./commits/create-git-tree.js');
9
9
  var getShaLastCommitOfBranch = require('./commits/get-sha-last-commit-of-branch.js');
10
10
  var getTreeByCommitSha = require('./commits/get-tree-by-commit-sha.js');
11
11
  var runNewCommitProcess = require('./commits/run-new-commit-process.js');
12
+ var getFileContent = require('./contents/get-file-content.js');
12
13
 
13
14
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
15
 
@@ -29,6 +30,7 @@ const githubSdk = (args) => {
29
30
  const createGitTree$1 = createGitTree.createGitTreeFactory(instance);
30
31
  const getShaLastCommitOfBranch$1 = getShaLastCommitOfBranch.getShaLastCommitOfBranchFactory(instance);
31
32
  const getTreeByCommitSha$1 = getTreeByCommitSha.getTreeByCommitShaFactory(instance);
33
+ const getFileContent$1 = getFileContent.getFileContentFactory(instance);
32
34
  const runNewCommitProcess$1 = runNewCommitProcess.runNewCommitProcessFactory({
33
35
  createGitBlob: createGitBlob$1,
34
36
  createGitCommit: createGitCommit$1,
@@ -43,6 +45,7 @@ const githubSdk = (args) => {
43
45
  getShaLastCommitOfBranch: getShaLastCommitOfBranch$1,
44
46
  getTreeByCommitSha: getTreeByCommitSha$1,
45
47
  runNewCommitProcess: runNewCommitProcess$1,
48
+ getFileContent: getFileContent$1,
46
49
  };
47
50
  };
48
51
 
@@ -1 +1 @@
1
- {"version":3,"file":"github.js","sources":["../../src/github/github.ts"],"sourcesContent":["import axios from 'axios';\n\nimport {\n createGitBlobFactory,\n createGitCommitFactory,\n createGitTreeFactory,\n getShaLastCommitOfBranchFactory,\n getTreeByCommitShaFactory,\n runNewCommitProcessFactory,\n} from './commits';\nimport type {\n CreateGitTree,\n CreateGitBlob,\n CreateGitCommit,\n GetTreeByCommitSha,\n GetShaLastCommitOfBranch,\n RunNewCommitProcess,\n} from './commits';\n\nexport type GithubSdkArgs = {\n owner: string;\n repo: string;\n token: string;\n};\n\nexport type GithubSdkInstance = {\n createGitBlob: CreateGitBlob;\n createGitCommit: CreateGitCommit;\n createGitTree: CreateGitTree;\n getShaLastCommitOfBranch: GetShaLastCommitOfBranch;\n getTreeByCommitSha: GetTreeByCommitSha;\n runNewCommitProcess: RunNewCommitProcess;\n};\n\nexport const githubSdk = (args: GithubSdkArgs) => {\n const { owner, repo, token } = args;\n\n const instance = axios.create({\n baseURL: `https://api.github.com/repos/${owner}/${repo}`,\n headers: {\n Accept: 'application/vnd.github+json',\n Authorization: `Bearer ${token}`,\n 'X-GitHub-Api-Version': '2022-11-28',\n },\n });\n\n const createGitBlob = createGitBlobFactory(instance);\n const createGitCommit = createGitCommitFactory(instance);\n const createGitTree = createGitTreeFactory(instance);\n const getShaLastCommitOfBranch = getShaLastCommitOfBranchFactory(instance);\n const getTreeByCommitSha = getTreeByCommitShaFactory(instance);\n\n const runNewCommitProcess = runNewCommitProcessFactory({\n createGitBlob,\n createGitCommit,\n createGitTree,\n getShaLastCommitOfBranch,\n getTreeByCommitSha,\n });\n\n return {\n createGitBlob,\n createGitCommit,\n createGitTree,\n getShaLastCommitOfBranch,\n getTreeByCommitSha,\n runNewCommitProcess,\n };\n};\n"],"names":["axios","createGitBlob","createGitBlobFactory","createGitCommit","createGitCommitFactory","createGitTree","createGitTreeFactory","getShaLastCommitOfBranch","getShaLastCommitOfBranchFactory","getTreeByCommitSha","getTreeByCommitShaFactory","runNewCommitProcess","runNewCommitProcessFactory"],"mappings":";;;;;;;;;;;;;;;;AAkCa,MAAA,SAAS,GAAG,CAAC,IAAmB,KAAI;IAC/C,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;AAEpC,IAAA,MAAM,QAAQ,GAAGA,yBAAK,CAAC,MAAM,CAAC;AAC5B,QAAA,OAAO,EAAE,CAAA,6BAAA,EAAgC,KAAK,CAAA,CAAA,EAAI,IAAI,CAAE,CAAA;AACxD,QAAA,OAAO,EAAE;AACP,YAAA,MAAM,EAAE,6BAA6B;YACrC,aAAa,EAAE,CAAU,OAAA,EAAA,KAAK,CAAE,CAAA;AAChC,YAAA,sBAAsB,EAAE,YAAY;AACrC,SAAA;AACF,KAAA,CAAC,CAAC;AAEH,IAAA,MAAMC,eAAa,GAAGC,kCAAoB,CAAC,QAAQ,CAAC,CAAC;AACrD,IAAA,MAAMC,iBAAe,GAAGC,sCAAsB,CAAC,QAAQ,CAAC,CAAC;AACzD,IAAA,MAAMC,eAAa,GAAGC,kCAAoB,CAAC,QAAQ,CAAC,CAAC;AACrD,IAAA,MAAMC,0BAAwB,GAAGC,wDAA+B,CAAC,QAAQ,CAAC,CAAC;AAC3E,IAAA,MAAMC,oBAAkB,GAAGC,4CAAyB,CAAC,QAAQ,CAAC,CAAC;IAE/D,MAAMC,qBAAmB,GAAGC,8CAA0B,CAAC;uBACrDX,eAAa;yBACbE,iBAAe;uBACfE,eAAa;kCACbE,0BAAwB;4BACxBE,oBAAkB;AACnB,KAAA,CAAC,CAAC;IAEH,OAAO;uBACLR,eAAa;yBACbE,iBAAe;uBACfE,eAAa;kCACbE,0BAAwB;4BACxBE,oBAAkB;6BAClBE,qBAAmB;KACpB,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"github.js","sources":["../../src/github/github.ts"],"sourcesContent":["import axios from 'axios';\n\nimport {\n createGitBlobFactory,\n createGitCommitFactory,\n createGitTreeFactory,\n getShaLastCommitOfBranchFactory,\n getTreeByCommitShaFactory,\n runNewCommitProcessFactory,\n} from './commits';\nimport type {\n CreateGitTree,\n CreateGitBlob,\n CreateGitCommit,\n GetTreeByCommitSha,\n GetShaLastCommitOfBranch,\n RunNewCommitProcess,\n} from './commits';\nimport { GetFileContent, getFileContentFactory } from './contents/get-file-content';\n\nexport type GithubSdkArgs = {\n owner: string;\n repo: string;\n token: string;\n};\n\nexport type GithubSdkInstance = {\n createGitBlob: CreateGitBlob;\n createGitCommit: CreateGitCommit;\n createGitTree: CreateGitTree;\n getShaLastCommitOfBranch: GetShaLastCommitOfBranch;\n getTreeByCommitSha: GetTreeByCommitSha;\n runNewCommitProcess: RunNewCommitProcess;\n getFileContent: GetFileContent;\n};\n\nexport const githubSdk = (args: GithubSdkArgs) => {\n const { owner, repo, token } = args;\n\n const instance = axios.create({\n baseURL: `https://api.github.com/repos/${owner}/${repo}`,\n headers: {\n Accept: 'application/vnd.github+json',\n Authorization: `Bearer ${token}`,\n 'X-GitHub-Api-Version': '2022-11-28',\n },\n });\n\n const createGitBlob = createGitBlobFactory(instance);\n const createGitCommit = createGitCommitFactory(instance);\n const createGitTree = createGitTreeFactory(instance);\n const getShaLastCommitOfBranch = getShaLastCommitOfBranchFactory(instance);\n const getTreeByCommitSha = getTreeByCommitShaFactory(instance);\n\n const getFileContent = getFileContentFactory(instance);\n\n const runNewCommitProcess = runNewCommitProcessFactory({\n createGitBlob,\n createGitCommit,\n createGitTree,\n getShaLastCommitOfBranch,\n getTreeByCommitSha,\n });\n\n return {\n createGitBlob,\n createGitCommit,\n createGitTree,\n getShaLastCommitOfBranch,\n getTreeByCommitSha,\n runNewCommitProcess,\n getFileContent,\n };\n};\n"],"names":["axios","createGitBlob","createGitBlobFactory","createGitCommit","createGitCommitFactory","createGitTree","createGitTreeFactory","getShaLastCommitOfBranch","getShaLastCommitOfBranchFactory","getTreeByCommitSha","getTreeByCommitShaFactory","getFileContent","getFileContentFactory","runNewCommitProcess","runNewCommitProcessFactory"],"mappings":";;;;;;;;;;;;;;;;;AAoCa,MAAA,SAAS,GAAG,CAAC,IAAmB,KAAI;IAC/C,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;AAEpC,IAAA,MAAM,QAAQ,GAAGA,yBAAK,CAAC,MAAM,CAAC;AAC5B,QAAA,OAAO,EAAE,CAAA,6BAAA,EAAgC,KAAK,CAAA,CAAA,EAAI,IAAI,CAAE,CAAA;AACxD,QAAA,OAAO,EAAE;AACP,YAAA,MAAM,EAAE,6BAA6B;YACrC,aAAa,EAAE,CAAU,OAAA,EAAA,KAAK,CAAE,CAAA;AAChC,YAAA,sBAAsB,EAAE,YAAY;AACrC,SAAA;AACF,KAAA,CAAC,CAAC;AAEH,IAAA,MAAMC,eAAa,GAAGC,kCAAoB,CAAC,QAAQ,CAAC,CAAC;AACrD,IAAA,MAAMC,iBAAe,GAAGC,sCAAsB,CAAC,QAAQ,CAAC,CAAC;AACzD,IAAA,MAAMC,eAAa,GAAGC,kCAAoB,CAAC,QAAQ,CAAC,CAAC;AACrD,IAAA,MAAMC,0BAAwB,GAAGC,wDAA+B,CAAC,QAAQ,CAAC,CAAC;AAC3E,IAAA,MAAMC,oBAAkB,GAAGC,4CAAyB,CAAC,QAAQ,CAAC,CAAC;AAE/D,IAAA,MAAMC,gBAAc,GAAGC,oCAAqB,CAAC,QAAQ,CAAC,CAAC;IAEvD,MAAMC,qBAAmB,GAAGC,8CAA0B,CAAC;uBACrDb,eAAa;yBACbE,iBAAe;uBACfE,eAAa;kCACbE,0BAAwB;4BACxBE,oBAAkB;AACnB,KAAA,CAAC,CAAC;IAEH,OAAO;uBACLR,eAAa;yBACbE,iBAAe;uBACfE,eAAa;kCACbE,0BAAwB;4BACxBE,oBAAkB;6BAClBI,qBAAmB;wBACnBF,gBAAc;KACf,CAAC;AACJ;;;;"}
package/dist/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@sparted/shared-library",
3
- "version": "1.0.8-alpha.0",
3
+ "version": "1.0.8-alpha.1",
4
4
  "repository": "git@github.com:Sparted/shared-library.git",
5
5
  "author": "Thomas <duprethomasfr@gmail.com>",
6
6
  "license": "MIT",
7
7
  "sideEffets": false,
8
- "main": "index.js",
9
- "module": "index.js",
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.js",
10
10
  "files": [
11
11
  "**/*",
12
12
  "**/**"
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@sparted/shared-library",
3
- "version": "1.0.8-alpha.0",
3
+ "version": "1.0.8-alpha.1",
4
4
  "repository": "git@github.com:Sparted/shared-library.git",
5
5
  "author": "Thomas <duprethomasfr@gmail.com>",
6
6
  "license": "MIT",
7
7
  "sideEffets": false,
8
- "main": "index.js",
9
- "module": "index.js",
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.js",
10
10
  "files": [
11
11
  "**/*",
12
12
  "**/**"
@@ -0,0 +1,50 @@
1
+ import type { AxiosInstance } from 'axios';
2
+
3
+ import { handleError } from '../commits/utils';
4
+
5
+ export type GetFileContentArgs = {
6
+ path: string;
7
+ branch: string;
8
+ };
9
+
10
+ type ApiResponse = {
11
+ encoding: 'base64' | 'utf-8';
12
+ content: string;
13
+ };
14
+
15
+ export type GetFileContentResponse = string;
16
+
17
+ export type GetFileContent = (args: GetFileContentArgs) => Promise<GetFileContentResponse>;
18
+
19
+ export type GetFileContentFactory = (instance: AxiosInstance) => GetFileContent;
20
+
21
+ /**
22
+ * Get the content of a file
23
+ *
24
+ * @param path the path of the file
25
+ * @param branch the branch of the file
26
+ * @returns GetFileContentResponse
27
+ * @throws validation-failed-or-the-endpoint-has-been-spammed
28
+ * @throws internal-server-error
29
+ * @throws forbidden
30
+ * @throws resource-not-found
31
+ */
32
+ export const getFileContentFactory: GetFileContentFactory = (instance) => async (args) => {
33
+ const { path, branch } = args;
34
+
35
+ try {
36
+ const { data } = await instance.get<ApiResponse>(`/contents/${path}`, {
37
+ params: {
38
+ ref: branch,
39
+ },
40
+ });
41
+
42
+ if (data.encoding === 'base64') {
43
+ return Buffer.from(data.content, 'base64').toString('utf-8');
44
+ }
45
+
46
+ return data.content;
47
+ } catch (error) {
48
+ throw handleError(error);
49
+ }
50
+ };
@@ -16,6 +16,7 @@ import type {
16
16
  GetShaLastCommitOfBranch,
17
17
  RunNewCommitProcess,
18
18
  } from './commits';
19
+ import { GetFileContent, getFileContentFactory } from './contents/get-file-content';
19
20
 
20
21
  export type GithubSdkArgs = {
21
22
  owner: string;
@@ -30,6 +31,7 @@ export type GithubSdkInstance = {
30
31
  getShaLastCommitOfBranch: GetShaLastCommitOfBranch;
31
32
  getTreeByCommitSha: GetTreeByCommitSha;
32
33
  runNewCommitProcess: RunNewCommitProcess;
34
+ getFileContent: GetFileContent;
33
35
  };
34
36
 
35
37
  export const githubSdk = (args: GithubSdkArgs) => {
@@ -50,6 +52,8 @@ export const githubSdk = (args: GithubSdkArgs) => {
50
52
  const getShaLastCommitOfBranch = getShaLastCommitOfBranchFactory(instance);
51
53
  const getTreeByCommitSha = getTreeByCommitShaFactory(instance);
52
54
 
55
+ const getFileContent = getFileContentFactory(instance);
56
+
53
57
  const runNewCommitProcess = runNewCommitProcessFactory({
54
58
  createGitBlob,
55
59
  createGitCommit,
@@ -65,5 +69,6 @@ export const githubSdk = (args: GithubSdkArgs) => {
65
69
  getShaLastCommitOfBranch,
66
70
  getTreeByCommitSha,
67
71
  runNewCommitProcess,
72
+ getFileContent,
68
73
  };
69
74
  };