Skip to content

Commit

Permalink
- docs
Browse files Browse the repository at this point in the history
- Adapt.iSource.randomAccess.stat uses Query.getDetail now to get the size and other stat information
  • Loading branch information
zacharygriffee committed Jan 23, 2024
1 parent 86d6cbb commit cbbf5a7
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 87 deletions.
2 changes: 1 addition & 1 deletion dist/adapt.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/all.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/components/Delete.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/components/FileExplorer.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/components/SaveAll.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/components/UploadTo.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/transport.min.js

Large diffs are not rendered by default.

52 changes: 8 additions & 44 deletions docs/adapt-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
* [Adapt](#Adapt) : <code>object</code>
* [.iSource](#Adapt.iSource) ⇒ <code>any</code>
* [.RandomAccessCollection](#Adapt.RandomAccessCollection)
* [.exports.setPack(_pack)](#Adapt.exports.setPack)
* [.importPack([url])](#Adapt.importPack) ⇒ <code>Promise.&lt;void&gt;</code>

<a name="Adapt.iSource"></a>

Expand All @@ -30,15 +28,21 @@ source = {
append, // Append a buffer to a source
append$, // An observable of append
entry, // To retrieve details of entry at key of source
// Your source should have an entry or get function to work
del, // Del key at source.
exists, // Whether the key of source exists
// Your source should have an exists, entry, or get function for exists to work.
ready, // Whether the source is ready to operate.
readdir, // Get an array of entries of the cwd of source
list, // Get an array of 'entry' details of the cwd of source
// Your source should have a readdir function/generator/observable
createReadStream, // Get a stream of data from a key of source.
factory // A function that returns a `string module` that defines how to
// install this storage source.
// Your source should have either a get or a native createReadStream(fileName, config)

factory // A function that returns a `string module` that defines how to
// install this storage source to make the source portable.
randomAccess // Create a random access storage interface of the iSource. You must enable randomAccess
// with Adapt.enableRandomAccess function before use.
// Properties
length // For supporting sources, get the length. Not fully implemented.
source // the raw source iSource wraps.
Expand Down Expand Up @@ -118,43 +122,3 @@ RAC.setCollection({
});
await RAC.exists("folder/preexistingFileInFolder.txt"); // true
```
<a name="Adapt.exports.setPack"></a>
### Adapt.exports.setPack(_pack) ⇒
Only necessary if you did not import the entire BYOSU namespace e.g. import * as BYOSU from "bring-your-own-storage-utilities";.
IF constructing a iSource from a factory string, you must import a pack.
Either use setPack if you already have Deploy.pack loaded.
Or, use importPack to import your own or from BYOSU repo.
**This is only ran once.
Repeated calls will be ignored**
**Kind**: static method of [<code>Adapt</code>](#Adapt)
**Returns**: void
| Param | Description |
| --- | --- |
| _pack | a preloaded Deploy.pack you have |
<a name="Adapt.importPack"></a>
### Adapt.importPack([url]) ⇒ <code>Promise.&lt;void&gt;</code>
Only necessary if you did not import the entire BYOSU namespace e.g. import * as BYOSU from "bring-your-own-storage-utilities";.
IF constructing a iSource from a factory string, you must import a pack. Either use setPack if you already have
Deploy.pack loaded. Or, use importPack to import your own or from BYOSU repo.
**This is only ran once.
Repeated calls will be ignored**
import errors should be caught by you
**Kind**: static method of [<code>Adapt</code>](#Adapt)
| Param | Default | Description |
| --- | --- | --- |
| [url] | <code>https://cdn.jsdelivr.net/npm/[email protected]/dist/deploy.min.js/+esm</code> | default is https://cdn.jsdelivr.net/npm/[email protected]/dist/deploy.min.js/+esm |
32 changes: 6 additions & 26 deletions lib/adapt/iSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,19 @@ function preFront(source, state = {}) {
* append, // Append a buffer to a source
* append$, // An observable of append
* entry, // To retrieve details of entry at key of source
* // Your source should have an entry or get function to work
* del, // Del key at source.
* exists, // Whether the key of source exists
* // Your source should have an exists, entry, or get function for exists to work.
* ready, // Whether the source is ready to operate.
* readdir, // Get an array of entries of the cwd of source
* list, // Get an array of 'entry' details of the cwd of source
* // Your source should have a readdir function/generator/observable
* createReadStream, // Get a stream of data from a key of source.
* // Your source should have either a get or a native createReadStream(fileName, config)
*
* factory // A function that returns a `string module` that defines how to
* // install this storage source.
* // install this storage source to make the source portable.
* randomAccess // Create a random access storage interface of the iSource. You must enable randomAccess
* // with Adapt.enableRandomAccess function before use.
* // Properties
Expand Down Expand Up @@ -155,28 +160,3 @@ export function iSource(source, state = {}) {
return preFront(source, state).cradle;
}


// await importPack();
//
// const src = ISource({
// factory: `
// const obj = {};
// export function get(x) {
// return obj[x];
// }
// export function put(x, buf) {
// obj[x] = buf;
// }
// export function del(x) {
// if (obj[x]) {
// delete obj[x];
// }
// }
// `
// });
//
// const result = await src.install();
// await result.put("hey", "hello");
// console.log(await result.get("hey"));


2 changes: 1 addition & 1 deletion lib/adapt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
* @namespace Adapt
*/

export * from "./fromRandomAccessCollection.js";
export * from "./randomAccessCollection.js";
// export * from "./fromRandomAccess.js";
export * from "./iSource.js";
5 changes: 2 additions & 3 deletions lib/adapt/isource/handleRandomAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ export function handleRandomAccess({
}

if (!!fileDetail.size && fileDetail.isFile)
req.callback(null)
req.callback(null);
else {
req.callback(new Error("File does not exist"));
}
},
async stat(req) {
try {
const size = (await get(file))?.length || 0;
req.callback(null, {size});
req.callback(null, await entry(file));
} catch (e) {
req.callback(e);
}
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions tests/adapt.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ test("isource randomaccess", async t => {
t.is(b4a.toString(result6), "1\0\0\0" + "5\0z\0\0\0");
// delete the file from the iSource perspective.
await src.del("readableAndWritable");
// Should not be able to access deleted file.
await t.exception(() => promisify(ras, "read", 1, 4));
// Should not be able to write either.
await t.exception(() => promisify(ras, "write", 1, b4a.from("1234")))
}
Expand Down

0 comments on commit cbbf5a7

Please sign in to comment.