-
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
Showing
19 changed files
with
609 additions
and
217 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 |
---|---|---|
|
@@ -62,3 +62,6 @@ nafs.d.ts | |
nafs.js | ||
|
||
types | ||
|
||
docs | ||
.vscode |
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,5 +1,11 @@ | ||
# nafs | ||
|
||
## 0.1.1 | ||
|
||
### Patch Changes | ||
|
||
- add s3fs class | ||
|
||
## 0.1.0 | ||
|
||
### Minor Changes | ||
|
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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
import { link } from '@ricsam/linkfs'; | ||
import type { IFs } from 'memfs'; | ||
import * as path from 'path'; | ||
import * as realFs from 'fs'; | ||
import * as realfs from 'fs'; | ||
import { parseUri } from '../../parse-uri'; | ||
|
||
export const createFileFs = (uri: string, fs?: IFs): IFs | typeof realFs => { | ||
const lfs = link(fs ?? realFs, [ | ||
export const createLinkFs = <T>(uri: `file://${string}`, fs: T): T => { | ||
const parsed = parseUri(uri); | ||
const lfs = link(fs, [ | ||
'/', | ||
uri.startsWith('/') ? uri : path.join(process.cwd(), uri), | ||
parsed.path.startsWith('/') | ||
? parsed.path | ||
: path.join(process.cwd(), parsed.path), | ||
]); | ||
return lfs; | ||
}; | ||
export const createFileFs = (uri: `file://${string}`) => { | ||
return createLinkFs(uri, realfs); | ||
}; |
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,21 +1,21 @@ | ||
import { expect, test } from 'bun:test'; | ||
import { createFsFromVolume, memfs, Volume } from 'memfs'; | ||
import { nafs } from '../../nafs'; | ||
import { createFsFromVolume, Volume } from 'memfs'; | ||
import { createLinkFs } from './file'; | ||
import { createMemFs } from './memory'; | ||
import { toTreeSync } from 'memfs/lib/print'; | ||
|
||
test('memfs', async () => { | ||
const fs = await nafs(':memory:'); | ||
const fs = createMemFs(); | ||
await fs.promises.writeFile('/test', 'test'); | ||
expect(await fs.promises.readFile('/test', 'utf-8')).toBe('test'); | ||
}); | ||
|
||
test('fs', async () => { | ||
const vol = new Volume(); | ||
const realFs = createFsFromVolume(vol); | ||
const fs = await nafs('file:///tmp', { | ||
fs: realFs, | ||
}); | ||
const memfs = createFsFromVolume(vol); | ||
const fs = createLinkFs('file:///tmp', memfs); | ||
await fs.promises.mkdir('/tmp', { recursive: true }); | ||
await fs.promises.writeFile('/tmp/test', 'test'); | ||
expect(await fs.promises.readFile('/tmp/test', 'utf-8')).toBe('test'); | ||
expect(await realFs.promises.readFile('/tmp/tmp/test', 'utf-8')).toBe('test'); | ||
expect(await memfs.promises.readFile('/tmp/tmp/test', 'utf-8')).toBe('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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { IFs } from 'memfs'; | ||
import { fs } from 'memfs'; | ||
import { fs, IFs } from 'memfs'; | ||
|
||
export const createMemFs = (): IFs => { | ||
return fs; | ||
}; |
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,52 @@ | ||
import { | ||
CreateBucketCommand, | ||
GetObjectCommand, | ||
ListBucketsCommand, | ||
ListObjectsV2Command, | ||
S3Client, | ||
} from '@aws-sdk/client-s3'; | ||
import { beforeAll, beforeEach, describe, expect, it } from 'bun:test'; | ||
import { S3Fs } from './s3fs'; | ||
|
||
describe('s3Fs LocalStack integration', () => { | ||
const LOCALSTACK_ENDPOINT = 'http://127.0.0.1:4566'; | ||
const BUCKET_NAME = 'test-bucket'; | ||
let s3Client: S3Client; | ||
|
||
beforeEach(() => { | ||
process.env.AWS_DEFAULT_REGION = 'us-east-1'; | ||
process.env.AWS_ACCESS_KEY_ID = 'test'; | ||
process.env.AWS_SECRET_ACCESS_KEY = 'test'; | ||
process.env.AWS_ENDPOINT_URL = LOCALSTACK_ENDPOINT; | ||
}); | ||
|
||
beforeAll(async () => { | ||
// Create a client for test verification | ||
s3Client = new S3Client({ | ||
endpoint: LOCALSTACK_ENDPOINT, | ||
region: 'us-east-1', | ||
credentials: { | ||
accessKeyId: 'test', | ||
secretAccessKey: 'test', | ||
}, | ||
forcePathStyle: true, | ||
}); | ||
|
||
// Create test bucket | ||
try { | ||
await s3Client.send( | ||
new CreateBucketCommand({ | ||
Bucket: BUCKET_NAME, | ||
}) | ||
); | ||
} catch (err) { | ||
// Bucket might already exist | ||
} | ||
}); | ||
|
||
it('should connect', async () => { | ||
const command = new ListBucketsCommand(); | ||
const response = await s3Client.send(command); | ||
expect(response.Buckets?.map(({ Name }) => Name)).toContain(BUCKET_NAME); | ||
}); | ||
}); |
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
Oops, something went wrong.