Skip to content

Commit

Permalink
rewrite the whole codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ricsam committed Dec 12, 2024
1 parent bb0d1f2 commit 33ae5ef
Show file tree
Hide file tree
Showing 37 changed files with 906 additions and 2,049 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
19 changes: 19 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: dev

on: [pull_request]

jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
services:
localstack:
image: localstack/localstack:s3-latest
ports:
- 4566:4566
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun test
- run: bun run build
37 changes: 24 additions & 13 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
name: Publish
name: publish

on:
release:
types: [published]
push:
branches:
- main

jobs:
build:
publish:
name: Publish
runs-on: ubuntu-latest
services:
localstack:
image: localstack/localstack:s3-latest
ports:
- 4566:4566
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: yarn install
- run: yarn run build
- run: npm publish --access public
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun test
- run: bun run build
- run: |
echo '@ricsam:registry=https://registry.npmjs.org' >> .npmrc
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' >> .npmrc
echo '//registry.npmjs.org/:always-auth=true' >> .npmrc
- name: changeset publish
run: npx changeset publish --access=public --registry=https://registry.npmjs.org/
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ index.d.ts
index.js
nafs.d.ts
nafs.js

types
20 changes: 16 additions & 4 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
example
dist
nodemon.json
tslint.json
*.test.*
.prettierrc
bun.lockb
CONTRIBUTING.md
CHANGELOG.md
tsconfig.build.json
tsconfig.json
.github
.changeset
LICENSE
matchers.d.ts
.gitignore
bunfig.toml
patch-dist-dirs.sh
happydom.ts
renovate.json
testing-library.ts
docker-compose.yml
12 changes: 12 additions & 0 deletions .swcrc.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://swc.rs/schema.json",
"module": {
"type": "commonjs"
},
"jsc": {
"target": "esnext",
"parser": {
"syntax": "typescript"
}
}
}
12 changes: 12 additions & 0 deletions .swcrc.mjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://swc.rs/schema.json",
"module": {
"type": "es6"
},
"jsc": {
"target": "esnext",
"parser": {
"syntax": "typescript"
}
}
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# nafs

## 0.1.0

### Minor Changes

- rewrite all code
7 changes: 0 additions & 7 deletions LICENCE

This file was deleted.

19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MIT License

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.
75 changes: 40 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,52 @@
# Node Active FS - nafs

```
Nafs is an abstraction of the [Node fs API](https://nodejs.org/api/fs.html) where you can choose to point the fs to a remote location like s3, postgres, logstash, kibana or locally like the local filesystem or in memory. Check the [compatiblility table](#supported-file-system-methods) to see which parts of the fs API has been implemented for each backend.

```bash
npm install nafs
yarn add nafs
```

### Example

```js
const { nafs, expressMiddleware } = require('nafs');
const express = require('express');

const localFs = nafs('file:///tmp/dev_storage');
const remoteFs = nafs('s3://key:secret@us-east-1/bucket_name/some/path');

const app = express();

app.use('/local-files', expressMiddleware(localFs.createReadStream));
app.use('/remote-files', expressMiddleware(remoteFs.createReadStream));

app.get('/', (req, res) => {
remoteFs.writeFile('/hello', 'Hello World').then(() => {
res.send('saved file to s3, check it out on /remote-files/hello or /read');
});
});
app.get('/read', (req, res) => {
removeFs.readFile('/hello').then((file) => {
res.send(file);
});
});
```

### Enable cache for remote data
```js
const remoteFs = nafs('s3://key:secret@us-east-1/bucket_name?cacheDir=/tmp/images');
const remoteFs = nafs('s3://key:secret@us-east-1/bucket_name');
const localFs = nafs('/tmp/some_folder');

console.time('hello');
await remoteFs.readFile('/hello')
console.timeEnd('hello'); /* 70 ms */
await remoteFs.promises.writeFile('/hello', 'Hello World');
await remoteFs.promises.readFile('/hello', 'utf8'); // Hello World

/* now cached */
console.time('hello');
await remoteFs.readFile('/hello')
console.timeEnd('hello'); /* 2 ms */
await localFs.promises.writeFile('/hello', 'Hello World');
await localFs.promises.readFile('/hello', 'utf8'); // Hello World
```



## Supported File System Methods
| Method | File System | Memory | S3 | PostgreSQL | Logstash | Kibana |
|---------------------|-------------|--------|-------|------------|-----------|---------|
| `promises.readFile` |||||||
| `promises.writeFile` |||||||
| `promises.unlink` |||||||
| `promises.rmdir` |||||||
| `promises.mkdir` |||||||
| `promises.readdir` |||||||
| `promises.stat` |||||||
| `promises.lstat` |||||||
| `promises.chmod` |||||||
| `promises.chown` |||||||
| `promises.utimes` |||||||
| `promises.rename` |||||||
| `promises.copyFile` |||||||
| `promises.symlink` |||||||
| `promises.readlink` |||||||
| `promises.truncate` |||||||
| `promises.access` |||||||
| `createReadStream` |||||||
| `createWriteStream` |||||||

✅ - Implemented
❌ - Not Implemented

File System and Memory implementations are provided via memfs and linkfs, supporting full Node.js fs API compatibility. S3 implementation currently supports basic file reading and writing operations. PostgreSQL, Logstash, and Kibana implementations are planned for future development.


Binary file added bun.lockb
Binary file not shown.
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3.8'
services:
s3:
image: localstack/localstack:s3-latest
ports:
- "4566:4566"
1 change: 0 additions & 1 deletion example/.env.dist

This file was deleted.

Binary file removed example/cat.jpeg
Binary file not shown.
93 changes: 0 additions & 93 deletions example/testServer.ts

This file was deleted.

10 changes: 0 additions & 10 deletions nodemon.json

This file was deleted.

Loading

0 comments on commit 33ae5ef

Please sign in to comment.