Skip to content

Commit

Permalink
Give more possibilieteies to converters (#17)
Browse files Browse the repository at this point in the history

    Rediefine Converters
    Rewrite json converter
    Rewrite yaml converter
    change internal handling of converter in file
    requriere nonce in plugins as symbol
  • Loading branch information
CordlessWool authored Apr 1, 2024
1 parent 0e10986 commit 238a261
Show file tree
Hide file tree
Showing 33 changed files with 410 additions and 161 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ jobs:
- name: Test
run: pnpm test:ci
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Commit Diff
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "auto fix lint errors"
commit_options: "--no-verify"
Expand Down
4 changes: 2 additions & 2 deletions adapters/in-memory/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@loom-io/in-memory-adapter",
"version": "0.7.1",
"version": "0.8.0",
"main": "dist/exports/lib.js",
"types": "dist/exports/lib.d.ts",
"author": "Cotton Coding",
Expand All @@ -27,7 +27,7 @@
"@loom-io/interface-tests": "workspace:^"
},
"peerDependencies": {
"@loom-io/core": "workspace:^0.7.0"
"@loom-io/core": "workspace:^0.8.0"
},
"dependencies": {
"@loom-io/common": "workspace:^"
Expand Down
3 changes: 2 additions & 1 deletion adapters/in-memory/src/exports/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default (key: string = 'memory://') => ({
const path = link.slice(key.length);
return source(path, Type);
}
}
},
nonce: Symbol('in-memory-source-adapter')
}) satisfies LoomSourceAdapter;
4 changes: 2 additions & 2 deletions adapters/minio/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@loom-io/minio-s3-adapter",
"version": "0.7.1",
"version": "0.8.0",
"main": "dist/exports/lib.js",
"types": "dist/exports/lib.d.ts",
"author": "Cotton Coding",
Expand Down Expand Up @@ -29,7 +29,7 @@
"@loom-io/test-utils": "workspace:^"
},
"peerDependencies": {
"@loom-io/core": "^0.7.0"
"@loom-io/core": "^0.8.0"
},
"dependencies": {
"@loom-io/common": "workspace:^",
Expand Down
19 changes: 1 addition & 18 deletions adapters/minio/src/core/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BucketItem, Client } from 'minio';
import type { Client } from 'minio';
import { ObjectDirent } from './object-dirent.js';
import { FileHandler } from './file-handler.js';
import { type SourceAdapter, type rmdirOptions, type ObjectDirentInterface, DirectoryNotEmptyException } from '@loom-io/core';
Expand Down Expand Up @@ -102,23 +102,6 @@ export class Adapter implements SourceAdapter {
});
}

protected async filesInDir(path: string): Promise<BucketItem[]> {
const pathWithTailSlash = path.endsWith('/') ? path : `${path}/`;
const bucketStream = await this.s3.listObjects(this.bucket, pathWithTailSlash);
return new Promise((resolve, reject) => {
const files: BucketItem[] = [];
bucketStream.on('data', (data) => {
files.push(data);
});
bucketStream.on('end', () => {
resolve(files);
});
bucketStream.on('error', (err) => {
reject(err);
});
});
}

async readdir(path: string): Promise<ObjectDirentInterface[]> {
const pathWithTailSlash = removePrecedingSlash(addTailSlash(path));
const bucketStream = await this.s3.listObjectsV2(this.bucket, pathWithTailSlash, false);
Expand Down
3 changes: 2 additions & 1 deletion adapters/minio/src/exports/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default (key: string = 's3://', bucket: string, s3config: S3Options): Loo
const path = link.slice(key.length);
return source(path, bucket, s3config, Type);
}
}
},
nonce: Symbol('minio-source-adapter')
});
4 changes: 2 additions & 2 deletions adapters/node-fs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@loom-io/node-filesystem-adapter",
"version": "0.7.1",
"version": "0.8.0",
"main": "dist/exports/lib.js",
"types": "dist/exports/lib.d.ts",
"author": "Cotton Coding",
Expand Down Expand Up @@ -32,7 +32,7 @@
"@faker-js/faker": "^8.4.1"
},
"peerDependencies": {
"@loom-io/core": "^0.7.0"
"@loom-io/core": "^0.8.0"
},
"exports": {
".": {
Expand Down
3 changes: 2 additions & 1 deletion adapters/node-fs/src/exports/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export default (key: string = 'file://', rootdir?: PathLike) => ({
const path = link.slice(key.length);
return source(path, rootdir, Type);
}
}
},
nonce: Symbol('node-fs-source-adapter')
}) satisfies LoomSourceAdapter;
14 changes: 7 additions & 7 deletions documentation/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export default defineConfig({
{ text: 'S3-Minio', link: '/adapter/minio-s3-adapter' }
]
},
// {
// text: 'Converter',
// items: [
// { text: 'JSON', link: '/converter/markdown-converter' },
// { text: 'YAML', link: '/converter/yaml-converter' }
// ]
// }
{
text: 'Converter',
items: [
{ text: 'JSON', link: '/converter/json-converter' },
{ text: 'YAML', link: '/converter/yaml-converter' }
]
},
{
text: 'Reference',
items: [
Expand Down
42 changes: 42 additions & 0 deletions documentation/converter/json-converter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
---

# JSON Converter

Adding this converter to read json-files as json.

::: code-group

```sh [npm]
npm add @loom-io/json-converter
```

```sh [pnpm]
pnpm add @loom-io/json-converter
```

```sh [bun]
bun add @loom-io/json-converter
```

:::

## Usage

Before usage you have to register the json converter

```ts
import Loom from "@loom-io/core";
import jsonConverter from "@loom-io/json-converter";

Loom.register(jsonConverter());
```

The you can read and write json files

```ts
const jsonFile = await Loom.file("memory://some/json/file.json");
const data = await jsonFile.json();
data.val = "test";
jsonFile.stringify(data);
```
42 changes: 42 additions & 0 deletions documentation/converter/yaml-converter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
---

# YAML Converter

Adding this converter to read yaml-files as json.

::: code-group

```sh [npm]
npm add @loom-io/yaml-converter
```

```sh [pnpm]
pnpm add @loom-io/yaml-converter
```

```sh [bun]
bun add @loom-io/yaml-converter
```

:::

## Usage

Before usage you have to register the yaml converter

```ts
import Loom from "@loom-io/core";
import yamlConverter from "@loom-io/yaml-converter";

Loom.register(yamlConverter());
```

The you can read and write yaml files with the ending `yaml` adn `yml`

```ts
const yamlFile = await Loom.file("memory://some/yaml/file.yaml");
const data = await yamlFile.json();
data.val = "test";
yamlFile.stringify(data);
```
4 changes: 2 additions & 2 deletions documentation/core/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ const bucketName = "loom-io-test-bucket";

Loom.register(s3MinioAdapter("s3://", bucketName, minioConfig));

Loom.register(jsonConverter);
Loom.register(yamlConverter);
Loom.register(jsonConverter());
Loom.register(yamlConverter());
```

Now we can dive deeper into loom-io and the storing system to access or create files and directories.
2 changes: 1 addition & 1 deletion packages/base-fs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@loom-io/base-fs",
"version": "0.7.1",
"version": "0.8.0",
"description": "Bundle of @loom-io modules for filesystem operations",
"main": "dist/exports/lib.js",
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions packages/base-fs/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import yamlConverter from '@loom-io/yaml-converter';
import fileSystemAdapter from '@loom-io/node-filesystem-adapter';

LoomIO.register(fileSystemAdapter('file://'));
LoomIO.register(jsonConverter);
LoomIO.register(yamlConverter);
LoomIO.register(yamlConverter());
LoomIO.register(jsonConverter());

export * from '@loom-io/core';

Expand Down
3 changes: 1 addition & 2 deletions packages/base-fs/tests/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,10 @@ describe.concurrent('test integration of bundle for interacting with filesystem'
await file.create();
const content = {test: 'content', test2: ['content', 'content2']};
await file.stringify(content);
expect(await file.text()).toBe('test: content\ntest2:\n - content\n - content2\n');
await expect(file.text()).resolves.toBe('test: content\ntest2:\n - content\n - content2\n');
await deleteRandomDirectory(dir);
});


});

});
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@loom-io/core",
"version": "0.7.1",
"version": "0.8.0",
"main": "dist/exports/lib.js",
"types": "dist/exports/lib.d.ts",
"author": "Cotton Coding",
Expand Down
Loading

0 comments on commit 238a261

Please sign in to comment.