-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cde0222
Showing
16 changed files
with
601 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
; http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
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,40 @@ | ||
name: Release and Publish | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- alpha | ||
- beta | ||
- next | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Lint files | ||
run: npm run lint | ||
|
||
- name: Generate type definitions | ||
run: npm run types | ||
|
||
- name: Run tests | ||
run: npm run test | ||
|
||
- name: Run semantic release | ||
run: npx semantic-release | ||
env: | ||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
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,33 @@ | ||
name: Run Lint and Tests | ||
|
||
on: | ||
push: | ||
branches-ignore: | ||
- main | ||
- alpha | ||
- beta | ||
- next | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macOS-latest, windows-latest] | ||
node-version: [18, 20] | ||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- run: npm install | ||
|
||
- run: npm run lint | ||
|
||
- run: npm run types | ||
|
||
- run: npm test |
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,16 @@ | ||
node_modules | ||
package-lock.json | ||
uploads | ||
tmp | ||
gcloud.json | ||
node_modules/**/* | ||
.DS_Store | ||
tmp/**/* | ||
.idea | ||
.idea/**/* | ||
*.iml | ||
*.log | ||
coverage | ||
.vscode | ||
.nyc_output/ | ||
.tap/ |
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,2 @@ | ||
package-lock=false | ||
save-exact=true |
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,13 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"tabWidth": 4, | ||
"overrides": [ | ||
{ | ||
"files": ["*.json", "*.yml"], | ||
"options": { | ||
"tabWidth": 2 | ||
} | ||
} | ||
] | ||
} |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Eik | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,135 @@ | ||
# @eik/sink-memory | ||
|
||
A Sink implementation that runs completely in memory, designed for automated tests. | ||
|
||
## Usage | ||
|
||
|
||
```sh | ||
npm install @eik/sink-memory | ||
``` | ||
|
||
|
||
```js | ||
const { pipeline } = require('stream'); | ||
const express = require("express"); | ||
const Sink = require("@eik/sink-memory"); | ||
|
||
const app = express(); | ||
const sink = new Sink(); | ||
|
||
app.get("/file.js", async (req, res, next) => { | ||
try { | ||
const file = await sink.read('/path/to/file/file.js'); | ||
pipeline(file.stream, res, (error) => { | ||
if (error) return next(error); | ||
}); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}); | ||
|
||
app.listen(8000); | ||
``` | ||
|
||
## API | ||
|
||
The sink instance has the following API: | ||
|
||
### .write(filePath, contentType) | ||
|
||
Method for writing a file to in-memory storage. | ||
|
||
This method takes the following arguments: | ||
|
||
* `filePath` - String - Path to the file to be stored - Required. | ||
* `contentType` - String - The content type of the file - Required. | ||
|
||
Resolves with a writable stream. | ||
|
||
```js | ||
const { pipeline } = require('stream); | ||
const fromStream = new SomeReadableStream(); | ||
const sink = new Sink({ ... }); | ||
try { | ||
const file = await sink.write('/path/to/file/file.js', 'application/javascript'); | ||
pipeline(fromStream, file.stream, (error) => { | ||
if (error) console.log(error); | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
``` | ||
### .read(filePath) | ||
Method for reading a file from storage. | ||
This method takes the following arguments: | ||
* `filePath` - String - Path to the file to be read - Required. | ||
Resolves with a [ReadFile][read-file] object which holds metadata about | ||
the file and a readable stream with the byte stream of the file on the | ||
`.stream` property. | ||
```js | ||
const { pipeline } = require('stream); | ||
|
||
const toStream = new SomeWritableStream(); | ||
const sink = new Sink({ ... }); | ||
|
||
try { | ||
const file = await sink.read('/path/to/file/file.js'); | ||
pipeline(file.stream, toStream, (error) => { | ||
if (error) console.log(error); | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
``` | ||
|
||
### .delete(filePath) | ||
|
||
Method for deleting a file in storage. | ||
|
||
This method takes the following arguments: | ||
|
||
* `filePath` - String - Path to the file to be deleted - Required. | ||
|
||
Resolves if file is deleted and rejects if file could not be deleted. | ||
|
||
```js | ||
const sink = new Sink({ ... }); | ||
|
||
try { | ||
await sink.delete('/path/to/file/file.js'); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
``` | ||
|
||
### .exist(filePath) | ||
|
||
Method for checking if a file exist in the storage. | ||
|
||
This method takes the following arguments: | ||
|
||
* `filePath` - String - Path to the file to be checked for existence - Required. | ||
|
||
Resolves if file exists and rejects if file does not exist. | ||
|
||
```js | ||
const sink = new Sink({ ... }); | ||
|
||
try { | ||
await sink.exist('/path/to/file/file.js'); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
``` | ||
|
||
[eik]: https://github.com/eik-lib | ||
[read-file]: https://github.com/eik-lib/common/blob/master/lib/classes/read-file.js |
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,22 @@ | ||
import prettierConfig from 'eslint-config-prettier'; | ||
import prettierPlugin from 'eslint-plugin-prettier/recommended'; | ||
import globals from 'globals'; | ||
import js from '@eslint/js'; | ||
|
||
export default [ | ||
js.configs.recommended, | ||
prettierConfig, | ||
prettierPlugin, | ||
{ | ||
languageOptions: { | ||
globals: { | ||
...globals.node, | ||
...globals.browser, | ||
global: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ignores: ['coverage/*', 'dist/*'], | ||
}, | ||
]; |
Oops, something went wrong.