Skip to content

Commit

Permalink
add doc for adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
CordlessWool committed Mar 29, 2024
1 parent 85bc698 commit c8d384a
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 17 deletions.
9 changes: 2 additions & 7 deletions adapters/minio/src/exports/lib.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { source, type S3Options } from '../core/source';
import { type Directory, PLUGIN_TYPE, type LoomSourceAdapter, LoomFile, MaybePromise } from '@loom-io/core';

export type S3MinioAdapterOptions = S3Options & {
bucket: string;
};

export default (key: string = 's3://', options: S3MinioAdapterOptions): LoomSourceAdapter => ({
export default (key: string = 's3://', bucket: string, s3config: S3Options): LoomSourceAdapter => ({
$type: PLUGIN_TYPE.SOURCE_ADAPTER,
source: (link: string, Type?: typeof Directory | typeof LoomFile): MaybePromise<Directory | LoomFile> | void => {
if(link.startsWith(key)) {
const path = link.slice(key.length);
const { bucket, ...s3options } = options;
return source(path, bucket, s3options, Type);
return source(path, bucket, s3config, Type);
}
}
});
5 changes: 1 addition & 4 deletions adapters/minio/test/source.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,4 @@ const s3config = {
};


testSource('s3://', S3MinioSourceAdapter(undefined, {
bucket: 'test-bucket',
...s3config
}));
testSource('s3://', S3MinioSourceAdapter(undefined, 'test-bucket', s3config));
6 changes: 3 additions & 3 deletions documentation/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { defineConfig } from 'vitepress'
// https://vitepress.dev/reference/site-config
export default defineConfig({
title: "loom-io",
description: "loom your file handling",
description: "weave your data access",
lastUpdated: true,
themeConfig: {
logo: "/loom-io.png",
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: 'Home', link: '/' },
{ text: 'Documentation', link: '/core/intro' }
{ text: 'Doc', link: '/core/intro' }
],
sidebar: [
{
Expand All @@ -28,7 +28,7 @@ export default defineConfig({
text: 'Source Adapter',
items: [
{ text: 'In-Memory', link: '/adapter/in-memory-adapter' },
{ text: 'Filesystem (node)', link: '/adapter/node-fs-adapter' },
{ text: 'Filesystem', link: '/adapter/node-filesystem-adapter' },
{ text: 'S3-Minio', link: '/adapter/minio-s3-adapter' }
]
},
Expand Down
34 changes: 34 additions & 0 deletions documentation/adapter/in-memory-adapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
---

# In Memory Adapter

This adapter was manly created for testing, but could also be used as a replacement for any other adapter. As the name told it stores all data in memory, which make it probably the fastest adapter.

::: code-group

```sh [npm]
npm add @loom-io/in-memory-adapter
```

```sh [pnpm]
pnpm add @loom-io/in-memory-adapter
```

```sh [bun]
bun add @loom-io/in-memory-adapter
```

:::

## Setup and Config

The adapter only has an default export and export a function to configure the adapter. In this case the only option is to set the key to reference it. As with all other adapters you can register it with different identifiers. The default identifier is `memory://`.

```ts
import Loom from "@loom-io/core";
import memoryAdapter from "@loom-io/in-memory-adapter";

Loom.register(memoryAdapter("my-memory://"));
Loom.register(memoryAdapter());
```
50 changes: 50 additions & 0 deletions documentation/adapter/minio-s3-adapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
---

# S3 Adapter

Connects your S3 as it is a filesystem storage and based on the minio library. Even if it based on the minio library you can use it with all other S3 Storage e.g.: Digital Ocean Spaces, Amazon S3

::: code-group

```sh [npm]
npm add @loom-io/minio-s3-adapter
```

```sh [pnpm]
pnpm add @loom-io/minio-s3-adapter
```

```sh [bun]
bun add @loom-io/minio-s3-adapter
```

:::

## Setup and config

Mainly the configuration is the same as with [minio](https://min.io/docs/minio/linux/developers/javascript/API.html). You just have setup a bucket name in advance. The default key to identify is `s3://`

```ts
import Loom from "@loom-io/core";
import s3Adapter from "@loom-io/s3-minio-adapter";

const s3ConfigMinio = {
endPoint: "play.min.io",
port: 9000,
useSSL: true,
accessKey: "Q3AM3UQ867SPQQA43P2F",
secretKey: "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
};

const s3ConfigDigitalOcean = {
endpoint: "ams3.digitaloceanspaces.com",
accessKey: "key",
secretKey: "secret",
};

// Set own key, bucket name and config for minio
Loom.register(memoryAdapter("my-s3://", "my-bucket", s3ConfigMinio));
// set default key (s3://), bucket name and digital ocean space config
Loom.register(memoryAdapter(undefined, "other-bucket", s3ConfigDigitalOcean));
```
36 changes: 36 additions & 0 deletions documentation/adapter/node-filesystem-adapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
---

# Filesystem Adapter

Access Files from you local filesystem. Don't be confused from the node in the package name, it should also work with bun, because it is node compatible, but there are plans to do a more Bun specific adapter. For now you should also use this for bun, because all adapter exchange able you can easily switch later to the Bun specific adapter if you want to.

::: code-group

```sh [npm]
npm add @loom-io/node-filesystem-adapter
```

```sh [pnpm]
pnpm add @loom-io/node-filesystem-adapter
```

```sh [bun]
bun add @loom-io/node-filesystem-adapter
```

:::

## Setup and config

The default key for this adapter is `file://`, by default the adapter sets your project directory as root directory (manly the directory you starts you server from), but you can set any other directory. This directory looks like and is accessed like you root directory, so you will not be able to break out of this directory.

```ts
import Loom from "@loom-io/core";
import filesystemAdapter from "@loom-io/node-filesystem-adapter";

// sets key to root:// and the root path to you filesystem root, be careful
Loom.register(filesystemAdapter("root://", "/"));
// use default config. Key is file:// and the "root"-Directory is your project root
Loom.register(filesystemAdapter());
```
9 changes: 6 additions & 3 deletions documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ layout: home
hero:
name: "loom-io"
text: handle your files
tagline: loom your file handling
tagline: weave your data access
actions:
- theme: brand
text: Introduction
link: /markdown-examples
link: /core/intro
- theme: alt
text: Get started
link: /api-examples
link: /core/install
- theme: alt
text: Github
link: https://github.com/cotton-coding/loom-io

features:
- title: Sources
Expand Down

0 comments on commit c8d384a

Please sign in to comment.