0.0.1332 • Published 1 month ago

bring-your-own-storage-utilities v0.0.1332

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

bring-your-own-storage-utilities (byosu)

Utilities for storage devices you bring on your own


Support the cause towards decentralization

bitcoin: bc1q9fpu6muvmg5fj76pyzg3ffjrmksnvfj3c0xva6



!! Alpha Stage !!

Currently, most functions are prototypes that need to be optimized and attempt to reduce dependency. They work just fine right now, but more can be done.



Demonstration

You can test this repo right now, in your browser. You can view the developer console (F12) when you enter to see the very tests you can run in node. It takes a bit of startup time because of the supporting test tools.

Live test in the browser

  • Loads an in-memory drive source in the browser
  • Tests every API listed below
  • Rollup and Svelte both compile and run right in the browser.
  • Shows alpha tests of wip source explorer component.

Installation

npm install bring-your-own-storage-utilities --save

It starts with a source that you bring

You can use the Adapt.iSource interface or if your source resembles the interface at all, it will probably work. Using the interface will ensure that the source is adapted to the utilities of the BYOSU Apis.

    // Example using a standard javascript object as a source.
    // See tests/adapt.js for this very thing at work.
    import {Adapt} from "bring-your-own-storage-utilities";
    const obj = {};
    const yourSource = Adapt.iSource({
        async get(key) {
            return obj[key];
        },
        async exists(key) {
            return !!obj[trimStart(key, "/")];
        },
        async put(key, buffer, config) {
            obj[key] = buffer;
        },
        async del(key) {
            if (obj[key]) {
                delete obj[key];
            }
        },
        * readdir(path) {
            path = trimEnd(coercePathAbsolute(path), "/") + "/";
            for (let key of Object.keys(obj)) {
                key = coercePathAbsolute(key);
                if (key.startsWith(path)) {
                    yield key.slice(path.length).split("/").shift();
                }
            }
        },
        // NEW. Experimental, this format may change.
        async exec(key, config = {}) {
            const {
              // Handler sticks out to public so that it can be 'micro-managed'
              handler: async (key, config) => {
                console.log(`"Executed ${key}`);
              } 
            } = config;
            
            // It would be good to get info on the file here
            // and do any security checks, validations,
            // or user notifications before sending to handler.
            
            return handler(key, config);
        }
    });

Your source after the above example will magically acquire much of the query API methods and can be used in any of the other api

API

import * as BYOSU from "bring-your-own-storage-utilities"

import {Adapt, Find, Query, Resolve, Transport, Deploy} from "bring-your-own-storage-utilities"

Query

import * as Query from "bring-your-own-storage-utilities/query"

You could say this is pretty similar to find. But, query is where you've found a resource now you need to understand that resource

API Documentation

  • Is it a file
  • Is it a folder
  • Get entry details of file
  • List recursively or read directory shallow.
  • Get mime-type of file with magic bytes

Find

import * as Find from "bring-your-own-storage-utilities/find"

The find api functions mainly finding stuff in the source storage or making it easier to find stuff.

API Documentation

  • Find files from a child directory up to the parents
  • Find files from a parent to the child
  • Find package.json file parent to the current working directory
  • Find node_modules parent to current working directory

Resolve

import * as Resolve from "bring-your-own-storage-utilities/resolve"

Have an id, specifier, import, name, hash table, whatever, this section should be for resolving these identifiers and indexers to a resource.

API Documentation

  • Resolve a bare module specifier and other files similar to node's require or es6's import
  • Collect modules from parent directories that have a node_modules folder
  • Load all package.json from child directory up to root directory
  • JsDelivr resolve of bare module specifiers
  • Turn string code into module.
  • Get dataUri of code or other resources

Adapt

Any adaptors that can help to use common sources. Or any adaptors to pipe the source to be consumed by other API.

API Documentation

  • iSource interface to wrap sources to extend functionality
  • Create a source from webpage importMap.
  • Wrap a collection of random-access-storage instances.

Transport

You need data from your source to go from point A to point B. Transport will help.

API Documentation

  • Fetch hook to fetch from your source or to create your own hooks.
  • Share your source over rpc socket

Deploy

You need to deploy something from your source to the end-user.

API Documentation

  • Rollup plugin to bundle files from your source
    • Utilizing dependency injection techniques. You can supply a rollup module, or this library will download it when Deploy.pack is used. See Deploy.setRollup in the api.
  • Svelte plugin to compile .svelte files from browser for sources in the browser.
    • Utilizing dependency injection techniques. You can supply the compile function from svelte library or this library will download one. See Deploy.setSvelteCompiler in the api.
  • ~ Terser plugin for rollup that works in browser ~ Disabled for now.
  • jsdelivr plugin that gets module specifier from CDN jsdelivr. This plugin will only resolve to module. Even if a module is cjs it will resolve as a module. If the module is natively esm module, you shouldn't have any problems with this plugin. MOST cjs just works.... but things can get dicey for some complex cjs javascript.

API included separately


Components

Svelte components for handling source storages.

API Documentation

  • File explorer (WIP)
  • Upload file from browser into your source
  • Download files from your source zipped.
  • Bootstrap.js that works with the way this library handles svelte

Todo

  • todo: examples for most functions
  • todo: ensure rxjs traversals doesn't have memory leaks.
  • todo: more coverage with tests including fails
  • todo: adapter to transform source into a node:fs interface
  • todo: support db like structures like hyperbee
  • todo: document on how sources are consumed and interfaces they should have
  • todo: separate very large deploy (currently 4mb) from the rest as a sdk
  • todo: thoroughly test every edge case with JsDelivr plugin/resolver

Test it

npm test

Distributed under the MIT license. See LICENSE for more information.

0.0.1332

1 month ago

0.0.1331

3 months ago

0.0.1330

3 months ago

0.0.1321

3 months ago

0.0.1320

3 months ago

0.0.1313

3 months ago

0.0.1312

3 months ago

0.0.1311

3 months ago

0.0.1307

3 months ago

0.0.1308

3 months ago

0.0.1310

3 months ago

0.0.1303

3 months ago

0.0.1304

3 months ago

0.0.1306

3 months ago

0.0.1302

3 months ago

0.0.1300

3 months ago

0.0.1202

4 months ago

0.0.1201

4 months ago

0.0.1200

4 months ago

0.0.1109

4 months ago

0.0.1107

4 months ago

0.0.1106

4 months ago

0.0.1108

4 months ago

0.0.1011

4 months ago

0.0.1010

4 months ago

0.0.1013

4 months ago

0.0.1012

4 months ago

0.0.1015

4 months ago

0.0.1014

4 months ago

0.0.1001

4 months ago

0.0.1003

4 months ago

0.0.1105

4 months ago

0.0.1104

4 months ago

0.0.1016

4 months ago

0.0.1101

4 months ago

0.0.1100

4 months ago

0.0.1103

4 months ago

0.0.1102

4 months ago

0.0.90

4 months ago

0.0.91

4 months ago

0.0.84

4 months ago

0.0.85

4 months ago

0.0.86

4 months ago

0.0.87

4 months ago

0.0.88

4 months ago

0.0.89

4 months ago

0.0.80

4 months ago

0.0.81

4 months ago

0.0.82

4 months ago

0.0.78

4 months ago

0.0.73

4 months ago

0.0.74

4 months ago

0.0.75

4 months ago

0.0.76

4 months ago

0.0.71

4 months ago

0.0.72

4 months ago

0.0.7

4 months ago

0.0.40

4 months ago

0.0.41

4 months ago

0.0.42

4 months ago

0.0.43

4 months ago

0.0.44

4 months ago

0.0.60

4 months ago

0.0.61

4 months ago

0.0.37

4 months ago

0.0.38

4 months ago

0.0.39

4 months ago

0.0.51

4 months ago

0.0.52

4 months ago

0.0.31

4 months ago

0.0.32

4 months ago

0.0.33

4 months ago

0.0.34

4 months ago

0.0.35

4 months ago

0.0.36

4 months ago

0.0.5

4 months ago

0.0.21

4 months ago

0.0.2

4 months ago

0.0.12

4 months ago

0.0.11

4 months ago

0.0.1

4 months ago