vscode-ojs icon indicating copy to clipboard operation
vscode-ojs copied to clipboard

fs/system apis

Open knoopx opened this issue 3 years ago • 5 comments

i see there's some fs module but I can't figure how to use. are fs/system apis supported in any way? what about running in a nodejs context? also what about CORS?

knoopx avatar Nov 12 '22 23:11 knoopx

In general if you:

import {xxx} from "@yyy/zzz";

... OR ...

data = FileAttachment("athletes.csv").csv({typed: true})

It will resolve back to ObservableHQ.com

But if you use relative paths:

import {xxx} from "./otherNotebook.ojsnb";

... OR ...

data = FileAttachment("./data/athletes.csv").csv({typed: true})

It will resolve locally.

Finally you can use "fetch" to get local files with relative paths or full URLs to get remote ones.

GordonSmith avatar Nov 13 '22 12:11 GordonSmith

You can also access all Observable StdLib functions: https://github.com/observablehq/stdlib

GordonSmith avatar Nov 13 '22 12:11 GordonSmith

in ojb/omd preview neither local or remote fetch works, local throws permission error and remote cors errors. FileAttachment works but you can't glob/list directories. unlocking net/fs/system apis will definitely make this project way more useful. have you tried mixing electron renderer+node integration with @hpcc-js/observable-md? about to try myself as this has same limitations as https://github.com/asg017/dataflow

knoopx avatar Nov 13 '22 14:11 knoopx

Sorry - I assumed you were using the ObservableJS Notebook feature (create a file with a ".ojsnb" file extension)...

If you give me a code snippet as an example, I will see what I can come up with - it should be relativly easy enough to find a workaround with the built in preview, but when exported to a standalone html page then you will be at the mercy of the usual CORs rules between hosting web server and API server.

GordonSmith avatar Nov 13 '22 15:11 GordonSmith

@knoopx FYI @hpcc-js/observable-md is being deprecated soon, you should switch to @hpcc-js/obersvablehq-compiler

GordonSmith avatar Nov 14 '22 06:11 GordonSmith