This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Build web, node, and production bundle #16
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8fe2880
Move to Webpack
mrcnski 26f230c
Build web and node targets
mrcnski 442d51e
Separate out web and node index.js files
mrcnski 41aab9b
Fix bundle issues
mrcnski 010aaab
Add test coverage
mrcnski 8690cf2
Fix eslint errors
mrcnski f9ac04c
Fix issues in node + move 'query' option from upload to base options
mrcnski 918a4f0
[BREAKING] Change skylink prefix to sia://
mrcnski 943a487
Don't bundle node and web targets, only for third "bundle" target
mrcnski d82ced9
Merge branch 'master' into webpack
mrcnski 56b1427
Fix tests
mrcnski 02d828b
Update readme
mrcnski 27cfece
Merge branch 'master' into webpack
mrcnski 8db8be8
Make prefix sia:// again (lost in merge)
mrcnski 9152ff4
Refactor node download logic
mrcnski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const { SkynetClient } = require(""); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,24 +1,21 @@ | ||||||||
import axios, { AxiosResponse } from "axios"; | ||||||||
import axios, { AxiosResponse, ResponseType } from "axios"; | ||||||||
import type { Method } from "axios"; | ||||||||
import { uploadFile, uploadDirectory, uploadDirectoryRequest, uploadFileRequest } from "./upload"; | ||||||||
|
||||||||
import { | ||||||||
downloadFile, | ||||||||
downloadFileHns, | ||||||||
getSkylinkUrl, | ||||||||
getHnsUrl, | ||||||||
getHnsresUrl, | ||||||||
getMetadata, | ||||||||
getFileContent, | ||||||||
getFileContentHns, | ||||||||
getFileContentRequest, | ||||||||
openFile, | ||||||||
openFileHns, | ||||||||
resolveHns, | ||||||||
} from "./download"; | ||||||||
import { getJSON, setJSON } from "./skydb"; | ||||||||
import { getEntry, getEntryUrl, setEntry } from "./registry"; | ||||||||
} from "../download"; | ||||||||
import { getJSON, setJSON } from "../skydb"; | ||||||||
import { getEntry, getEntryUrl, setEntry } from "../registry"; | ||||||||
|
||||||||
import { addUrlQuery, defaultPortalUrl, makeUrl } from "./utils/url"; | ||||||||
import { addUrlQuery, defaultPortalUrl, makeUrl } from "../utils/url"; | ||||||||
import { CustomUploadOptions, UploadRequestResponse } from "../upload"; | ||||||||
|
||||||||
/** | ||||||||
* Custom client options. | ||||||||
|
@@ -54,40 +51,45 @@ export type RequestConfig = CustomClientOptions & { | |||||||
skykeyName?: string; | ||||||||
skykeyId?: string; | ||||||||
headers?: Record<string, unknown>; | ||||||||
responseType?: ResponseType; | ||||||||
transformRequest?: (data: unknown) => string; | ||||||||
transformResponse?: (data: string) => Record<string, unknown>; | ||||||||
}; | ||||||||
|
||||||||
/** | ||||||||
* The Skynet Client which can be used to access Skynet. | ||||||||
* The base Skynet Client which can be used to access Skynet. | ||||||||
*/ | ||||||||
export class SkynetClient { | ||||||||
export abstract class SkynetClient { | ||||||||
// TODO: This is currently the url of the skapp and not the portal. It should be the value of 'skynet-portal-api' header. This will be a promise, which will be a breaking change. | ||||||||
portalUrl: string; | ||||||||
customOptions: CustomClientOptions; | ||||||||
|
||||||||
// Set methods (defined in other files). | ||||||||
|
||||||||
// Upload | ||||||||
uploadFile = uploadFile; | ||||||||
protected uploadFileRequest = uploadFileRequest; | ||||||||
uploadDirectory = uploadDirectory; | ||||||||
protected uploadDirectoryRequest = uploadDirectoryRequest; | ||||||||
|
||||||||
// Download | ||||||||
downloadFile = downloadFile; | ||||||||
downloadFileHns = downloadFileHns; | ||||||||
getSkylinkUrl = getSkylinkUrl; | ||||||||
getHnsUrl = getHnsUrl; | ||||||||
getHnsresUrl = getHnsresUrl; | ||||||||
getMetadata = getMetadata; | ||||||||
getFileContent = getFileContent; | ||||||||
getFileContentHns = getFileContentHns; | ||||||||
protected getFileContentRequest = getFileContentRequest; | ||||||||
openFile = openFile; | ||||||||
openFileHns = openFileHns; | ||||||||
resolveHns = resolveHns; | ||||||||
|
||||||||
// Upload | ||||||||
abstract uploadFileContent( | ||||||||
this: SkynetClient, | ||||||||
fileContents: string, | ||||||||
fileName: string, | ||||||||
customOptions?: CustomUploadOptions | ||||||||
): Promise<UploadRequestResponse>; | ||||||||
protected abstract uploadFileContentRequest( | ||||||||
this: SkynetClient, | ||||||||
fileContents: string, | ||||||||
fileName: string, | ||||||||
customOptions?: CustomUploadOptions | ||||||||
): Promise<AxiosResponse>; | ||||||||
|
||||||||
// SkyDB | ||||||||
db = { | ||||||||
getJSON: getJSON.bind(this), | ||||||||
|
@@ -109,6 +111,9 @@ export class SkynetClient { | |||||||
* @param [customOptions] Configuration for the client. | ||||||||
*/ | ||||||||
constructor(portalUrl: string = defaultPortalUrl(), customOptions: CustomClientOptions = {}) { | ||||||||
if (!portalUrl) { | ||||||||
portalUrl = defaultPortalUrl(); | ||||||||
} | ||||||||
Comment on lines
+114
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need that, you already have that in the argument list
Suggested change
|
||||||||
this.portalUrl = portalUrl; | ||||||||
this.customOptions = customOptions; | ||||||||
} | ||||||||
|
@@ -159,6 +164,7 @@ export class SkynetClient { | |||||||
headers, | ||||||||
auth, | ||||||||
onUploadProgress, | ||||||||
responseType: config.responseType, | ||||||||
transformRequest: config.transformRequest, | ||||||||
transformResponse: config.transformResponse, | ||||||||
|
||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { downloadFileHnsToPath, downloadFileToPath, downloadFileToPathRequest } from "../download/node"; | ||
import { | ||
uploadDirectoryFromPath, | ||
uploadDirectoryFromPathRequest, | ||
uploadFileFromPath, | ||
uploadFileFromPathRequest, | ||
uploadFileContent, | ||
uploadFileContentRequest, | ||
} from "../upload/node"; | ||
import { SkynetClient as Client } from "./index"; | ||
|
||
export class SkynetClient extends Client { | ||
// Download | ||
downloadFileToPath = downloadFileToPath; | ||
downloadFileHnsToPath = downloadFileHnsToPath; | ||
protected downloadFileToPathRequest = downloadFileToPathRequest; | ||
|
||
// Upload | ||
uploadDirectoryFromPath = uploadDirectoryFromPath; | ||
protected uploadDirectoryFromPathRequest = uploadDirectoryFromPathRequest; | ||
uploadFileFromPath = uploadFileFromPath; | ||
protected uploadFileFromPathRequest = uploadFileFromPathRequest; | ||
uploadFileContent = uploadFileContent; | ||
protected uploadFileContentRequest = uploadFileContentRequest; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { downloadFile, downloadFileHns, openFile, openFileHns } from "../download/web"; | ||
import { | ||
uploadFile, | ||
uploadDirectory, | ||
uploadDirectoryRequest, | ||
uploadFileRequest, | ||
uploadFileContent, | ||
uploadFileContentRequest, | ||
} from "../upload/web"; | ||
import { SkynetClient as Client } from "./index"; | ||
|
||
export class SkynetClient extends Client { | ||
// Download | ||
downloadFile = downloadFile; | ||
downloadFileHns = downloadFileHns; | ||
openFile = openFile; | ||
openFileHns = openFileHns; | ||
|
||
// Upload | ||
uploadFile = uploadFile; | ||
protected uploadFileRequest = uploadFileRequest; | ||
uploadDirectory = uploadDirectory; | ||
protected uploadDirectoryRequest = uploadDirectoryRequest; | ||
uploadFileContent = uploadFileContent; | ||
protected uploadFileContentRequest = uploadFileContentRequest; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this wasn't meant to be committed lol. The deploy script is a separate PR