Skip to content

Commit 238a261

Browse files
authored
Give more possibilieteies to converters (#17)
Rediefine Converters Rewrite json converter Rewrite yaml converter change internal handling of converter in file requriere nonce in plugins as symbol
1 parent 0e10986 commit 238a261

File tree

33 files changed

+410
-161
lines changed

33 files changed

+410
-161
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ jobs:
3535
- name: Test
3636
run: pnpm test:ci
3737
- name: Upload coverage reports to Codecov
38-
uses: codecov/codecov-action@v3
39-
env:
40-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
38+
uses: codecov/codecov-action@v4
39+
with:
40+
token: ${{ secrets.CODECOV_TOKEN }}
4141
- name: Commit Diff
42-
uses: stefanzweifel/git-auto-commit-action@v4
42+
uses: stefanzweifel/git-auto-commit-action@v5
4343
with:
4444
commit_message: "auto fix lint errors"
4545
commit_options: "--no-verify"

adapters/in-memory/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@loom-io/in-memory-adapter",
3-
"version": "0.7.1",
3+
"version": "0.8.0",
44
"main": "dist/exports/lib.js",
55
"types": "dist/exports/lib.d.ts",
66
"author": "Cotton Coding",
@@ -27,7 +27,7 @@
2727
"@loom-io/interface-tests": "workspace:^"
2828
},
2929
"peerDependencies": {
30-
"@loom-io/core": "workspace:^0.7.0"
30+
"@loom-io/core": "workspace:^0.8.0"
3131
},
3232
"dependencies": {
3333
"@loom-io/common": "workspace:^"

adapters/in-memory/src/exports/lib.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export default (key: string = 'memory://') => ({
88
const path = link.slice(key.length);
99
return source(path, Type);
1010
}
11-
}
11+
},
12+
nonce: Symbol('in-memory-source-adapter')
1213
}) satisfies LoomSourceAdapter;

adapters/minio/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@loom-io/minio-s3-adapter",
3-
"version": "0.7.1",
3+
"version": "0.8.0",
44
"main": "dist/exports/lib.js",
55
"types": "dist/exports/lib.d.ts",
66
"author": "Cotton Coding",
@@ -29,7 +29,7 @@
2929
"@loom-io/test-utils": "workspace:^"
3030
},
3131
"peerDependencies": {
32-
"@loom-io/core": "^0.7.0"
32+
"@loom-io/core": "^0.8.0"
3333
},
3434
"dependencies": {
3535
"@loom-io/common": "workspace:^",

adapters/minio/src/core/adapter.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { BucketItem, Client } from 'minio';
1+
import type { Client } from 'minio';
22
import { ObjectDirent } from './object-dirent.js';
33
import { FileHandler } from './file-handler.js';
44
import { type SourceAdapter, type rmdirOptions, type ObjectDirentInterface, DirectoryNotEmptyException } from '@loom-io/core';
@@ -102,23 +102,6 @@ export class Adapter implements SourceAdapter {
102102
});
103103
}
104104

105-
protected async filesInDir(path: string): Promise<BucketItem[]> {
106-
const pathWithTailSlash = path.endsWith('/') ? path : `${path}/`;
107-
const bucketStream = await this.s3.listObjects(this.bucket, pathWithTailSlash);
108-
return new Promise((resolve, reject) => {
109-
const files: BucketItem[] = [];
110-
bucketStream.on('data', (data) => {
111-
files.push(data);
112-
});
113-
bucketStream.on('end', () => {
114-
resolve(files);
115-
});
116-
bucketStream.on('error', (err) => {
117-
reject(err);
118-
});
119-
});
120-
}
121-
122105
async readdir(path: string): Promise<ObjectDirentInterface[]> {
123106
const pathWithTailSlash = removePrecedingSlash(addTailSlash(path));
124107
const bucketStream = await this.s3.listObjectsV2(this.bucket, pathWithTailSlash, false);

adapters/minio/src/exports/lib.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export default (key: string = 's3://', bucket: string, s3config: S3Options): Loo
88
const path = link.slice(key.length);
99
return source(path, bucket, s3config, Type);
1010
}
11-
}
11+
},
12+
nonce: Symbol('minio-source-adapter')
1213
});

adapters/node-fs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@loom-io/node-filesystem-adapter",
3-
"version": "0.7.1",
3+
"version": "0.8.0",
44
"main": "dist/exports/lib.js",
55
"types": "dist/exports/lib.d.ts",
66
"author": "Cotton Coding",
@@ -32,7 +32,7 @@
3232
"@faker-js/faker": "^8.4.1"
3333
},
3434
"peerDependencies": {
35-
"@loom-io/core": "^0.7.0"
35+
"@loom-io/core": "^0.8.0"
3636
},
3737
"exports": {
3838
".": {

adapters/node-fs/src/exports/lib.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export default (key: string = 'file://', rootdir?: PathLike) => ({
99
const path = link.slice(key.length);
1010
return source(path, rootdir, Type);
1111
}
12-
}
12+
},
13+
nonce: Symbol('node-fs-source-adapter')
1314
}) satisfies LoomSourceAdapter;

documentation/.vitepress/config.mts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ export default defineConfig({
2929
{ text: 'S3-Minio', link: '/adapter/minio-s3-adapter' }
3030
]
3131
},
32-
// {
33-
// text: 'Converter',
34-
// items: [
35-
// { text: 'JSON', link: '/converter/markdown-converter' },
36-
// { text: 'YAML', link: '/converter/yaml-converter' }
37-
// ]
38-
// }
32+
{
33+
text: 'Converter',
34+
items: [
35+
{ text: 'JSON', link: '/converter/json-converter' },
36+
{ text: 'YAML', link: '/converter/yaml-converter' }
37+
]
38+
},
3939
{
4040
text: 'Reference',
4141
items: [
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
---
3+
4+
# JSON Converter
5+
6+
Adding this converter to read json-files as json.
7+
8+
::: code-group
9+
10+
```sh [npm]
11+
npm add @loom-io/json-converter
12+
```
13+
14+
```sh [pnpm]
15+
pnpm add @loom-io/json-converter
16+
```
17+
18+
```sh [bun]
19+
bun add @loom-io/json-converter
20+
```
21+
22+
:::
23+
24+
## Usage
25+
26+
Before usage you have to register the json converter
27+
28+
```ts
29+
import Loom from "@loom-io/core";
30+
import jsonConverter from "@loom-io/json-converter";
31+
32+
Loom.register(jsonConverter());
33+
```
34+
35+
The you can read and write json files
36+
37+
```ts
38+
const jsonFile = await Loom.file("memory://some/json/file.json");
39+
const data = await jsonFile.json();
40+
data.val = "test";
41+
jsonFile.stringify(data);
42+
```

0 commit comments

Comments
 (0)